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

igorvd

02/14/2019, 5:12 PM
how do I define the routings on another module? I try to add this to the
application.conf
Copy code
modules = [ com.example.ApplicationKt.module, com.example.user.UserModuleKt.module ]
and create this extension into the UserModule file:
Copy code
package com.example.user

fun Application.module() {
    routing {
        route("/users") {
            get {
                call.respondText("Users", ContentType.Text.Plain)
            }
        }
    }
}
when I try to conect to the /users endpoint, I'm getting a 404 error 😕
c

cy

02/14/2019, 5:19 PM
This actually should work. Need to be investigated...
i

igorvd

02/14/2019, 5:26 PM
Do you want a project copy? It's my first time using Ktor, I was basically just reading the documentation and testing stuff, so I'm not sure if I'm doing something wrong
c

cy

02/14/2019, 5:28 PM
Do any routes actually work? Or just routes from extra modules do not work?
i

igorvd

02/14/2019, 5:32 PM
the routes on the
Application.kt
file works, with this content:
Copy code
fun main(args: Array<String>) {
    val server = embeddedServer(Netty, port = 9000) {

        routing {

            trace { application.log.trace(it.buildText()) }

            get("/") {
                
                call.respondText("Hello World!", ContentType.Text.Plain)

            }

        }
    }
    server.start(wait = true)
}
when I cut the route
/users
from the other file and paste here, works too
c

cy

02/15/2019, 8:45 AM
People usually extract modules to separate functions and simply invoke them from main module functions this is why this bug wasn't discovered yet.
Will fix that, thanks
i

igorvd

02/15/2019, 5:03 PM
Cool. Thanks for your feedback 🙂
3 Views