Hi, guys! Recently started to develop full stack a...
# server
v
Hi, guys! Recently started to develop full stack application using kotlin with ktor as backend. And now i have a problem with cors policy
Copy code
Access to fetch at '<http://127.0.0.1:8080/api/run?userId=root&profile=test>' from origin '<http://localhost:3000>' 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
As i understand, i should add origin to list of allowed origins in my backend app, i do this that way
Copy code
install(CORS){
        method(HttpMethod.Get)
        method(<http://HttpMethod.Post|HttpMethod.Post>, )
        method(HttpMethod.Delete)
        anyHost()
        host("localhost")
    }
But this dont work. This is headers of response from js clinet
Copy code
'Origin': '<http://localhost:3000>',
                'Content-Type': 'application/json',
                'Accept': 'application/json',
                'Access-Control-Request-Headers': 'Content-Type, Authorization'
Can anyone help me please?
a
Can you remove the host localhost line and try again?
a
also, while installing CORS allow the authorization header as well