Ryan Brink
06/03/2023, 12:50 AMfun Application.myApplicationModule() {
install(CallLogging) {
level = Level.TRACE
}
install(CORS) {
allowHeader(HttpHeaders.ContentType)
anyHost()
}
routing {
route("/testing") {
post {
call.respond("hi")
}
}
}
}
but, if I run curl -i -X OPTIONS <http://localhost:8080>
I get a 404 not found. If I instead do curl -i -X OPTIONS <http://localhost:8080/testing>
I get a 405. Based on the cors doc, it makes it sound like options should be autoconfigured, but they are not. Does anyone know what I am doing wrong?Trevor Stone
06/03/2023, 1:00 AMTrevor Stone
06/03/2023, 1:03 AM/testing
registered as a post
but curl will default to get
Trevor Stone
06/03/2023, 1:03 AMpost
to get
and you should see a hi
responseRyan Brink
06/03/2023, 1:11 AMDiagnosing <http://localhost:8080/graphql>
âš OPTIONS response is missing header 'access-control-allow-methods: POST'
(📫 Interested in previewing a local tunnel to bypass CORS requirements? Please let us know at <https://docs.google.com/forms/d/e/1FAIpQLScUCi3PdMerraiy6GpD-QiC_9KEKVHr4oDL5Vef5fIvzqqQWg/viewform> )
Trevor Stone
06/03/2023, 1:14 AMOPTIONS
request which isn't supported by defaultTrevor Stone
06/03/2023, 1:14 AMRyan Brink
06/03/2023, 1:16 AMRyan Brink
06/03/2023, 1:16 AMTrevor Stone
06/03/2023, 1:17 AM/graphql
route registered, you don't have it handling an options request, and you aren't returning the headersRyan Brink
06/03/2023, 1:18 AMfun main() {
embeddedServer(CIO, port = 8080, module = Application::myApplicationModule).start(wait = true)
}
fun Application.myApplicationModule() {
install(CallLogging) {
level = Level.TRACE
}
install(CORS) {
allowHeader(HttpHeaders.ContentType)
allowMethod(HttpMethod.Options)
anyHost()
}
routing {
route("/") {
post {
val models = getOgModels()
val sdl = generateCustomObjectGraph(models).toString()
val schema = parseSdl(sdl).validateAsSchema().value!!.toIntrospectionSchema().toJson()
call.response.header("content-type", "application/json")
call.respondText(schema)
}
}
}
}
And the diagnosis tool
npx diagnose-endpoint@1.1.0 --endpoint=<http://localhost:8080>
Ryan Brink
06/03/2023, 1:18 AMRyan Brink
06/03/2023, 1:18 AM/graphql
in case that was somehow interfering with the pluginRyan Brink
06/03/2023, 1:19 AMAleksei Tirman [JB]
06/06/2023, 9:20 AMOrigin
and Access-Control-Request-Method
headers to satisfy CORS:
curl -i -H "Origin: <http://origin.com>" -H "Access-Control-Request-Method: POST" -X OPTIONS <http://127.0.0.1:8080/>