Sebastien Leclerc Lavallee
06/28/2022, 9:05 PM/account
or /events
that I would call at <http://localhost:8080/events>
for example.
Now I have deployed it on a server at something like <https://some.domain/api/>
and I call endpoints at <https://some.domain/api/events>
. Now there aren’t any route that is matched when I call that endpoint. I have an intercept where I print the request path and it says the path is /api/events
which makes sense.
My question is, how do I tell ktor that it’s hosted under a specific path ? In this case /api
. This way, it would strip the /api
part and the route would get matched and my code would run as expected.
Thanks 🙂Aleksei Tirman [JB]
06/29/2022, 8:29 AMrootPath
in the server environment to solve your problem. Here is an example:
embeddedServer(Netty, applicationEngineEnvironment {
rootPath = "/api"
connector {
port = 4444
}
module {
routing {
get("/events") {
call.respondText { "Hello" }
}
}
}
}).start(true)
Sebastien Leclerc Lavallee
06/29/2022, 1:23 PMrootPath
inside the application.conf
file? On the same level as the port.Aleksei Tirman [JB]
06/29/2022, 1:25 PMSebastien Leclerc Lavallee
06/29/2022, 1:29 PMfun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
And my understanding is that it gets the port from the application.conf
and probably other configuration.
Now is having the embeddedServer inside the main function is a better way?
embeddedServer(Netty, applicationEngineEnvironment { } )
ThanksAleksei Tirman [JB]
06/29/2022, 1:32 PMSebastien Leclerc Lavallee
06/29/2022, 1:32 PM