Vasily Scherbakov
05/23/2021, 12:40 PMAccess 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
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
'Origin': '<http://localhost:3000>',
'Content-Type': 'application/json',
'Accept': 'application/json',
'Access-Control-Request-Headers': 'Content-Type, Authorization'
Can anyone help me please?Júlio Santos
05/23/2021, 11:54 PMinstall(CORS) {
method(HttpMethod.Options)
method(<http://HttpMethod.Post|HttpMethod.Post>)
method(HttpMethod.Get)
method(HttpMethod.Put)
method(HttpMethod.Delete)
method(HttpMethod.Head)
header(HttpHeaders.AccessControlAllowHeaders)
header(HttpHeaders.ContentType)
header(HttpHeaders.AccessControlAllowOrigin)
header(HttpHeaders.AccessControlAllowMethods)
header("userToken")
allowCredentials = true
allowNonSimpleContentTypes = true
hosts.addAll(initHostsOrigins())
}
initHostsOrigins
, where I get the hosts from my application.conf
fileprivate fun initHostsOrigins() = ConfigFactory.load().getString("cors.allowed-origins")
.split(",")
.stream()
.map { it.trim() }
.filter { it.isNotBlank() }
.collect(Collectors.toList())
application.conf
file looks like thiscors: {
allowed-origins: "<http://localhost:3000>,<http://localhost:8080>"
}
Vasily Scherbakov
05/26/2021, 7:03 PMJúlio Santos
05/26/2021, 11:38 PM