I want to do a very basic thing with Ktor: add the following configuration:
"Access-Control-Allow-Origin": "*"
"Access-Control-Allow-Methods": "*"
"Access-Control-Allow-Headers": "*"
I went through the CORS documentation of Ktor and I have not found how to achieve it.
The following configuration works with GET requests, but POST request fail.
install(CORS) {
anyHost()
}
Exploring the APIs through my IDE didn't help much.
Q: How to disable CORS completelly in Ktor?
CodePudding user response:
anyHost()
is equivalent for "Access-Control-Allow-Origin": "*"
allowHeaders { true }
is equivalent for "Access-Control-Allow-Headers": "*"
HttpMethod.DefaultMethods.forEach { method(it) }
is equivalent for "Access-Control-Allow-Methods": "*"