Hi everyone. I'm trying to enable some routes onl...
# http4k
p
Hi everyone. I'm trying to enable some routes only when conditions are met (a service exists). What would be the right way to do this? Here's what I tried (the test fails).
Copy code
@Test
    fun `should allow nesting routes`() {
        val NO_ROUTES = object : HttpHandler {
            override fun invoke(p1: Request): Response {
                return Response(Status.NOT_FOUND)
            }
        }

        val serviceDependantRoutes = if(true) {
            routes(
                    "/hello" bind Method.GET to { Response(OK).body("OK ") }
            )
        } else {
            NO_ROUTES
        }

        val routes = routes(
                "/hello" bind Method.GET to { Response(OK).body("OK ") },
                "/service" bind serviceDependantRoutes
        )
        val helloResponse = routes(Request(Method.GET, "/service/hello"))
        assertEquals(helloResponse.status, OK)
    }