mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-08-07 21:01:14 +00:00
add webserver, etc...
- add ktor webserver - package is subpackaged.
This commit is contained in:
45
webserver/build.gradle.kts
Normal file
45
webserver/build.gradle.kts
Normal file
@@ -0,0 +1,45 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
kotlin("plugin.serialization").version("2.0.0")
|
||||
}
|
||||
|
||||
group = project.rootProject.group
|
||||
version = project.rootProject.version
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
val ktorVersion = "2.3.12"
|
||||
|
||||
dependencies {
|
||||
implementation("io.ktor:ktor-server-core:$ktorVersion")
|
||||
implementation("io.ktor:ktor-server-netty:$ktorVersion")
|
||||
implementation("io.ktor:ktor-server-websockets:$ktorVersion")
|
||||
implementation("io.ktor:ktor-server-swagger:$ktorVersion")
|
||||
implementation("io.ktor:ktor-server-content-negotiation:$ktorVersion")
|
||||
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
|
||||
implementation("io.ktor:ktor-server-cors:$ktorVersion")
|
||||
implementation("io.ktor:ktor-server-swagger:$ktorVersion")
|
||||
|
||||
implementation("io.swagger.codegen.v3:swagger-codegen-generators:1.0.50")
|
||||
|
||||
// https://mvnrepository.com/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0-RC")
|
||||
// https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-reflect
|
||||
implementation("org.jetbrains.kotlin:kotlin-reflect:2.0.0")
|
||||
|
||||
// https://mvnrepository.com/artifact/ch.qos.logback/logback-classic
|
||||
implementation("ch.qos.logback:logback-classic:1.5.6")
|
||||
|
||||
implementation(project(":common"))
|
||||
|
||||
testImplementation(kotlin("test"))
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
kotlin {
|
||||
jvmToolchain(21)
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
package space.mori.chzzk_bot.webserver
|
||||
|
||||
import io.ktor.http.*
|
||||
import io.ktor.serialization.kotlinx.json.*
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.engine.*
|
||||
import io.ktor.server.netty.*
|
||||
import io.ktor.server.plugins.contentnegotiation.*
|
||||
import io.ktor.server.plugins.cors.routing.*
|
||||
import io.ktor.server.plugins.swagger.*
|
||||
import io.ktor.server.routing.*
|
||||
import io.ktor.server.websocket.*
|
||||
import kotlinx.serialization.json.Json
|
||||
import space.mori.chzzk_bot.webserver.routes.apiRoutes
|
||||
|
||||
val server = embeddedServer(Netty, port = 8080) {
|
||||
install(WebSockets)
|
||||
install(ContentNegotiation) {
|
||||
json(Json {
|
||||
prettyPrint = true
|
||||
isLenient = true
|
||||
})
|
||||
}
|
||||
install(CORS) {
|
||||
anyHost()
|
||||
allowHeader(HttpHeaders.ContentType)
|
||||
}
|
||||
routing {
|
||||
apiRoutes()
|
||||
swaggerUI("swagger-ui/index.html", "openapi/documentation.yaml") {
|
||||
options {
|
||||
version = "1.1.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun start() {
|
||||
server.start(wait = true)
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
server.stop()
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
package space.mori.chzzk_bot.webserver.routes
|
||||
|
||||
import io.ktor.http.*
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.response.*
|
||||
import io.ktor.server.routing.*
|
||||
|
||||
fun Routing.apiRoutes() {
|
||||
route("/") {
|
||||
get {
|
||||
call.respondText("Hello World!", status = HttpStatusCode.OK)
|
||||
}
|
||||
}
|
||||
route("/health") {
|
||||
get {
|
||||
call.respondText("OK", status= HttpStatusCode.OK)
|
||||
}
|
||||
}
|
||||
}
|
35
webserver/src/main/resources/openapi/documentation.yaml
Normal file
35
webserver/src/main/resources/openapi/documentation.yaml
Normal file
@@ -0,0 +1,35 @@
|
||||
openapi: "3.1.0"
|
||||
info:
|
||||
title: "chzzk_bot API"
|
||||
description: "chzzk_bot API"
|
||||
version: "1.0.0"
|
||||
servers:
|
||||
- url: "http://localhost:8080"
|
||||
paths:
|
||||
/:
|
||||
get:
|
||||
summary: "Webroot"
|
||||
description: "Main page of this api"
|
||||
responses:
|
||||
"200":
|
||||
description: "OK"
|
||||
content:
|
||||
text/plain:
|
||||
schema:
|
||||
type: "string"
|
||||
examples:
|
||||
Example#1:
|
||||
value: "Hello World!"
|
||||
/health:
|
||||
get:
|
||||
description: "Health Check endpoint"
|
||||
responses:
|
||||
"200":
|
||||
description: "OK"
|
||||
content:
|
||||
text/plain:
|
||||
schema:
|
||||
type: "string"
|
||||
examples:
|
||||
Example#1:
|
||||
value: "OK"
|
Reference in New Issue
Block a user