整理Route
This commit is contained in:
parent
a361978101
commit
448a504723
@ -10,9 +10,10 @@ fun main(args: Array<String>): Unit =
|
|||||||
|
|
||||||
@Suppress("unused") // application.conf references the main function. This annotation prevents the IDE from marking it as unused.
|
@Suppress("unused") // application.conf references the main function. This annotation prevents the IDE from marking it as unused.
|
||||||
fun Application.module() {
|
fun Application.module() {
|
||||||
configureSecurity()
|
configureModules()
|
||||||
configureSerialization()
|
configureCharacter()
|
||||||
configureRouting()
|
configureRankTable()
|
||||||
|
configureUser()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun md5encode(password: String): String {
|
fun md5encode(password: String): String {
|
||||||
|
|||||||
40
src/main/kotlin/com/ray650128/plugins/CharacterRouting.kt
Normal file
40
src/main/kotlin/com/ray650128/plugins/CharacterRouting.kt
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package com.ray650128.plugins
|
||||||
|
|
||||||
|
import io.ktor.serialization.gson.*
|
||||||
|
import io.ktor.server.plugins.contentnegotiation.*
|
||||||
|
import io.ktor.server.response.*
|
||||||
|
import io.ktor.server.application.*
|
||||||
|
import io.ktor.server.auth.*
|
||||||
|
import io.ktor.server.routing.*
|
||||||
|
|
||||||
|
fun Application.configureCharacter() {
|
||||||
|
routing {
|
||||||
|
route("/api") {
|
||||||
|
route("/v1") {
|
||||||
|
get("/characters") {
|
||||||
|
call.respond(mapOf("hello" to "world"))
|
||||||
|
}
|
||||||
|
|
||||||
|
route("/character") {
|
||||||
|
get("/{id}") {
|
||||||
|
call.respond(mapOf("hello" to "world"))
|
||||||
|
}
|
||||||
|
|
||||||
|
authenticate {
|
||||||
|
post {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
put {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
delete("/{id}") {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
45
src/main/kotlin/com/ray650128/plugins/Modules.kt
Normal file
45
src/main/kotlin/com/ray650128/plugins/Modules.kt
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
package com.ray650128.plugins
|
||||||
|
|
||||||
|
import io.ktor.server.auth.*
|
||||||
|
import io.ktor.server.auth.jwt.*
|
||||||
|
import com.ray650128.JwtConfig
|
||||||
|
import io.ktor.http.*
|
||||||
|
import io.ktor.serialization.gson.*
|
||||||
|
import io.ktor.server.application.*
|
||||||
|
import io.ktor.server.plugins.contentnegotiation.*
|
||||||
|
import io.ktor.server.plugins.cors.routing.*
|
||||||
|
|
||||||
|
fun Application.configureModules() {
|
||||||
|
|
||||||
|
authentication {
|
||||||
|
jwt {
|
||||||
|
realm = JwtConfig.jwtRealm
|
||||||
|
verifier(JwtConfig.verifier)
|
||||||
|
validate { credential ->
|
||||||
|
if (credential.payload.audience.contains(JwtConfig.jwtAudience)) {
|
||||||
|
JWTPrincipal(credential.payload)
|
||||||
|
} else null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
install(ContentNegotiation) {
|
||||||
|
gson {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
install(CORS) {
|
||||||
|
allowHeader(HttpHeaders.AccessControlAllowOrigin)
|
||||||
|
allowHeader(HttpHeaders.Accept)
|
||||||
|
allowHeader(HttpHeaders.ContentType)
|
||||||
|
anyHost()
|
||||||
|
allowMethod(HttpMethod.Options)
|
||||||
|
allowMethod(HttpMethod.Get)
|
||||||
|
allowMethod(HttpMethod.Post)
|
||||||
|
allowMethod(HttpMethod.Put)
|
||||||
|
allowMethod(HttpMethod.Delete)
|
||||||
|
allowHeader(HttpHeaders.Authorization)
|
||||||
|
allowCredentials = true
|
||||||
|
allowNonSimpleContentTypes = true
|
||||||
|
}
|
||||||
|
}
|
||||||
38
src/main/kotlin/com/ray650128/plugins/RankTableRouting.kt
Normal file
38
src/main/kotlin/com/ray650128/plugins/RankTableRouting.kt
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package com.ray650128.plugins
|
||||||
|
|
||||||
|
import io.ktor.server.application.*
|
||||||
|
import io.ktor.server.auth.*
|
||||||
|
import io.ktor.server.response.*
|
||||||
|
import io.ktor.server.routing.*
|
||||||
|
|
||||||
|
fun Application.configureRankTable() {
|
||||||
|
routing {
|
||||||
|
route("/api") {
|
||||||
|
route("/v1") {
|
||||||
|
route("/table") {
|
||||||
|
get("/{authorId}") {
|
||||||
|
call.respond(mapOf("hello" to "world"))
|
||||||
|
}
|
||||||
|
|
||||||
|
get("/{authorId}/{date}") {
|
||||||
|
call.respond(mapOf("hello" to "world"))
|
||||||
|
}
|
||||||
|
|
||||||
|
authenticate {
|
||||||
|
post {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
put {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
delete("/{id}") {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,26 +0,0 @@
|
|||||||
package com.ray650128.plugins
|
|
||||||
|
|
||||||
import io.ktor.server.auth.*
|
|
||||||
import io.ktor.server.auth.jwt.*
|
|
||||||
import com.auth0.jwt.JWT
|
|
||||||
import com.auth0.jwt.algorithms.Algorithm
|
|
||||||
import com.ray650128.JwtConfig
|
|
||||||
import io.ktor.server.sessions.*
|
|
||||||
import io.ktor.server.response.*
|
|
||||||
import io.ktor.server.application.*
|
|
||||||
import io.ktor.server.routing.*
|
|
||||||
|
|
||||||
fun Application.configureSecurity() {
|
|
||||||
|
|
||||||
authentication {
|
|
||||||
jwt {
|
|
||||||
realm = JwtConfig.jwtRealm
|
|
||||||
verifier(JwtConfig.verifier)
|
|
||||||
validate { credential ->
|
|
||||||
if (credential.payload.audience.contains(JwtConfig.jwtAudience)) {
|
|
||||||
JWTPrincipal(credential.payload)
|
|
||||||
} else null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
package com.ray650128.plugins
|
|
||||||
|
|
||||||
import io.ktor.serialization.gson.*
|
|
||||||
import io.ktor.server.plugins.contentnegotiation.*
|
|
||||||
import io.ktor.server.response.*
|
|
||||||
import io.ktor.server.application.*
|
|
||||||
import io.ktor.server.routing.*
|
|
||||||
|
|
||||||
fun Application.configureSerialization() {
|
|
||||||
install(ContentNegotiation) {
|
|
||||||
gson {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
routing {
|
|
||||||
get("/json/gson") {
|
|
||||||
call.respond(mapOf("hello" to "world"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -16,23 +16,7 @@ import io.ktor.server.response.*
|
|||||||
import io.ktor.server.routing.*
|
import io.ktor.server.routing.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
fun Application.configureRouting() {
|
fun Application.configureUser() {
|
||||||
|
|
||||||
install(CORS) {
|
|
||||||
allowHeader(HttpHeaders.AccessControlAllowOrigin)
|
|
||||||
allowHeader(HttpHeaders.Accept)
|
|
||||||
allowHeader(HttpHeaders.ContentType)
|
|
||||||
anyHost()
|
|
||||||
allowMethod(HttpMethod.Options)
|
|
||||||
allowMethod(HttpMethod.Get)
|
|
||||||
allowMethod(HttpMethod.Post)
|
|
||||||
allowMethod(HttpMethod.Put)
|
|
||||||
allowMethod(HttpMethod.Delete)
|
|
||||||
allowHeader(HttpHeaders.Authorization)
|
|
||||||
allowCredentials = true
|
|
||||||
allowNonSimpleContentTypes = true
|
|
||||||
}
|
|
||||||
|
|
||||||
routing {
|
routing {
|
||||||
route("/api") {
|
route("/api") {
|
||||||
route("/v1") {
|
route("/v1") {
|
||||||
Loading…
Reference in New Issue
Block a user