https://kotlinlang.org logo
#ktor
Title
# ktor
t

Tom.K

05/07/2021, 4:32 PM
Hey, I'm working on my own personal website that uses Ktor framework. I have few questions at this moment: - Is it possible to add and remove routes from embedded Ktor server during runtime? - Is it possible to wrap a servlet through Ktor server that relays the request to Ktor client that relays it to servlet? I've tried wrapping JGit HTTP servlet, but I had no luck. - Should I consider separating a single Ktor server into frontend (providing HTML content) and backend server (providing API and authorization with MsgPack/JSON)?
m

Miquel Àngel Román

05/07/2021, 8:02 PM
Answering your first question: Well you certainly cannot "unrun" the function lambda that declares a route; but you can dynamically return a value such as:
Copy code
var toggled = false
get("/yourRoute"){

    toggled = !toggled
    if(toggled) call.respond(404) else actualCall(call)
}
Possibilities are endless; you can check something on the DB, or ping another server etc...
On your last question: What do you exactly mean? SoC is always good, so I would personally split them or create some sort of structre that implements MVC or similar
t

Tom.K

05/07/2021, 8:21 PM
For the last one: I currently have a server that provides frontend by returning HTML content and backend with database stuff as plain objects. I'll try to consider separating them for better separation of concerns as you said it. Though, I'll have to consider using something to communicate between them, most likely I'll need to use some RPC framework. Thanks for response.