Hey guys, not sure if I'm missing something, but I...
# http4k
p
Hey guys, not sure if I'm missing something, but I ran into a weird issue with the Apache Backend. Setting up my server with
Copy code
val server = DebuggingFilters.PrintRequest()
        .then(ServerFilters.CatchAll())
        .then(ServerFilters.RequestTracing())
        .then(CorsFilter)
        .then(PowerSocketSwitcherApp(powerSwitch, config.sockets))
        .asServer(SunHttp(9090))
        .start()
Will let me access it from inside the local network. But when I swap out SunHttp for Apache, I get a response "not authoritative". I just found that issue, but it's more centered around the work load it seems: https://github.com/http4k/http4k/issues/481 Btw, my CorsFilter:
Copy code
val CorsFilter = ServerFilters.Cors(
        CorsPolicy(
            originPolicy = AllowAllOriginPolicy,
            headers = listOf("*"),
            methods = Method.values().toList(),
            credentials = false
        )
    )
Do you have any hints? Thanks in advance!
s
I couldn't reproduce, at least not with my adapted example:
Copy code
import org.http4k.client.JavaHttpClient
import org.http4k.core.Method
import org.http4k.core.Request
import org.http4k.core.Response
import org.http4k.core.Status
import org.http4k.core.then
import org.http4k.filter.CorsPolicy
import org.http4k.filter.DebuggingFilters
import org.http4k.filter.ServerFilters
import org.http4k.server.ApacheServer
import org.http4k.server.asServer

fun main() {
    DebuggingFilters.PrintRequest()
        .then(ServerFilters.CatchAll())
        .then(ServerFilters.RequestTracing())
        .then(ServerFilters.Cors(CorsPolicy.UnsafeGlobalPermissive))
        .then { Response(Status.OK) }
        .asServer(ApacheServer(9090)).start().use {
            val client = JavaHttpClient()
            println(client(Request(Method.GET, "<http://localhost:9090>")))
        }
}
Can you please try that and let us know if we're missing something?
p
That's working and my tests are working too. But as soon as my client has a different IP (e.g. calling the service from my smartphone) I get the mentioned error.
I thought it must have something to do with my network, but the error doesn't appear when I switch Apache for SunHttp.
r
Not sure that it helps but I also had a problem accessing localhost in cloudfoundry with apache server https://kotlinlang.slack.com/archives/C5AL3AKUY/p1602518040044800 I gave up and switched to Undertow.