s4nchez
03/27/2020, 10:18 AM/tokens
path twice. This should work:
class TokensRouter(private val tokensCommandHandler: TokensCommandHandler) {
operator fun invoke(): RoutingHttpHandler =
ServerFilters.Cors(CorsPolicy.UnsafeGlobalPermissive).then(routes(
"/tokens" bind <http://Method.POST|Method.POST> to tokensCommandHandler::invoke
))
}
import org.http4k.core.Method
import org.http4k.core.Request
import org.http4k.core.Response
import org.http4k.core.Status.Companion.I_M_A_TEAPOT
import org.http4k.core.then
import org.http4k.filter.CorsPolicy
import org.http4k.filter.ServerFilters
import org.http4k.routing.bind
import org.http4k.routing.routes
fun main() {
val app = ServerFilters.Cors(CorsPolicy.UnsafeGlobalPermissive).then(routes(
"/tokens" bind <http://Method.POST|Method.POST> to { Response(I_M_A_TEAPOT).body("ok") }
))
val request = Request(Method.OPTIONS, "/tokens")
val response = app(request)
println(response)
val postRequest = Request(<http://Method.POST|Method.POST>, "/tokens")
val postResponse = app(postRequest)
println(postResponse)
}
sahil Lone
03/27/2020, 10:20 AMs4nchez
03/27/2020, 10:36 AMorg.http4k.routing.Router#match
is doing.val corsRoute = routes("/{:.*}" bind <http://Method.POST|Method.POST> to { Response(I_M_A_TEAPOT).body("ok") })
.with(ServerFilters.Cors(CorsPolicy.UnsafeGlobalPermissive))
val app = routes(
"/bob" bind Method.GET to { Response(ACCEPTED) },
"/tokens" bind corsRoute)
println(app(Request(Method.GET, "/bob")))
println(app(Request(Method.OPTIONS, "/bob")))
println(app(Request(Method.OPTIONS, "/tokens")))
println(app(Request(<http://Method.POST|Method.POST>, "/tokens")))
sahil Lone
03/27/2020, 10:39 AMs4nchez
03/27/2020, 10:40 AM/bob
because it doesn't undertand OPTIONSsahil Lone
03/27/2020, 10:43 AMs4nchez
03/27/2020, 10:45 AM