Reputation: 21
when i add a random header to a reply in Hapi.js, it works fine.
However when I am trying to add to a header that already exisits, it is not sent.
It is almost as if i didn't even add it.
reply("Hello World)
.header("Random-Header", "Random Reply")
.header("Access-Control-Expose-Headers","Authorization");
Is there a way to add the Access-Control-Expose-Headers - Authorization?
Upvotes: 2
Views: 1014
Reputation: 31
If you want to use CORS headers you should enable/configure them in route
options (CORS headers disabled by default):
server.route({
method: 'GET',
path: '/',
handler: function(request, reply) { ... },
config: {
cors: {
origin: ['*'], // list of valid domains
exposedHeaders: ['Authorization'] // 'Access-Control-Expose-Headers'
}
}
});
Read more about defaults and options in hapi documentation.
or you can enable CORS on all routes:
new Hapi.Server({
connections: {
routes: {
cors: {
origin: ['*'],
exposedHeaders: ['Authorization']
}
}
}
})
Upvotes: 3