Nodejs Hapi - How to enable cross origin access control
Where did you put cors=true
? Could you add some code?
Without know exactly where you've put cors = true
, this bit of code may help you:
server.connection({ routes: { cors: true } })
Or try adding the allowed cors in the config section of your route.
server.route({
config: {
cors: {
origin: ['*'],
additionalHeaders: ['cache-control', 'x-requested-with']
}
},
Take a look at this question: hapi.js Cors Pre-flight not returning Access-Control-Allow-Origin header
Addition to @James111's answer,
Even if that answer doesn't work for you. check for additional Auth headers that you are sending.
In my case it was X_AUTH_TOKEN
, so in additionalHeaders
you might want to add your custom header as well.
e.g.
additionalHeaders: ['cache-control', 'x-requested-with', 'X_AUTH_TOKEN']