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

Amaan

05/20/2022, 1:20 AM
If I want to host different apps/apis on different subdomains, how do I do that and test it locally? I tried doing the following:
Copy code
fun Application.configureRouting() {
    routing {
        host("localhost:8080") {
            home()
        }
        host("chat.localhost:8080") {
            chat()
        }
    }
}
but that doesn't seem to work when I test it on my browser.
a

Aleksei Tirman [JB]

05/20/2022, 9:55 AM
You have to pass a port as the second argument for the
host
method or remove it from the first argument.
a

Amaan

05/20/2022, 6:32 PM
Hmm, that seems to work, but not when I run it in my docker container. I have the following code now:
Copy code
val host = environment.config.host
val port = environment.config.port
routing {
    host(host, port) {
        home()
    }
    host("chat.$host", port) {
        chat()
    }
}
and in
application.conf
I have
Copy code
ktor {
    deployment {
        host = localhost
...
When I run a docker container, I can't access the localhost of the container from my localhost endpoint (I put in
chat.localhost:8080
, but I can't get access to the one in the container). However, when I just run
Main.kt
, it works just fine. The reason I want to use a container is so I can host it online and make sure the subdomains work there too. Removing the host name from the
application.conf
works to access
0.0.0.0:8080
, but then I can't access the
chat
subdomain.
17 Views