I am working HapiJs Restful web service and trying to enable cors so any client even from different domain can consume my services. I tried cors=true in server connection object but didn't work.
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']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With