andylamax
08/16/2020, 10:23 PMinstall(CORS) {
method(HttpMethod.Options)
method(HttpMethod.Patch)
method(HttpMethod.Delete)
headersOf(HttpHeaders.AccessControlAllowOrigin, "*")
headersOf(
HttpHeaders.AccessControlAllowMethods to listOf(
HttpMethod.Get.value,
HttpMethod.Post.value,
HttpMethod.Put.value,
HttpMethod.Patch.value,
HttpMethod.Delete.value,
HttpMethod.Head.value,
HttpMethod.Options.value
),
HttpHeaders.AccessControlAllowHeaders to listOf(
HttpHeaders.Origin, HttpHeaders.ContentType, HttpHeaders.XAuthToken
)
)
anyHost()
}
Doens't help me when I am trying to fetch to my restful api with ktor
. How do I allow Cross Origin Resource Sharing?
I still get
Access to fetch at '<http://192.168.43.218:8080/v0.1.0/auth/users/exists>' from origin '<http://localhost:8088>' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
I have tested by disabling the web security. It works, but I don't wanna do that.
Can someone please tell me how?
Rest Api: ktor-server
Client: ktor-client-js
Browser: Chromium,OperaMilan Hruban
08/17/2020, 5:53 AMandylamax
08/17/2020, 8:41 AM