hapi icon indicating copy to clipboard operation
hapi copied to clipboard

"Request header field Content-Type is not allowed by Access-Control-Allow-Headers in preflight response."

Open rainabba opened this issue 11 years ago • 9 comments

My connection config was using the cors: { origin: [] } approach to allow specific hosts when I upgrade to Hapi 11. I got some CORS errors (as I expected given the breaking changes for 11), but I continue to get this error even when using defaults ( cors: true ) and even the following which explictly providers headers to be allowed. This only seems to be happening with some of my calls though and it appears to be the cases where OPTIONS is being used.

The response header does no include access-control-allow-headers, but does include access-control-expose-headers and access-control-allow-origin (which is set to my calling hostname so the wildcard seems to be working).

Am I missing something still? Shouldn't access-control-allow-headers be included?

cors: {
    origin: [ '*' ],
    headers: ['Authorization', 'Content-Type', 'If-None-Match']
}

rainabba avatar Oct 18 '15 20:10 rainabba

Console log here: https://github.com/hapijs/hapi/blob/master/lib/cors.js#L131

And let me know if that gives a clue.

hueniverse avatar Oct 18 '15 22:10 hueniverse

If not today, I will be sure to look into this tomorrow.

rainabba avatar Oct 20 '15 22:10 rainabba

Recent fixes should over this.

hueniverse avatar Oct 23 '15 18:10 hueniverse

Simply posting as follows with angular js ....

var config = { method: 'POST', url: this.url + 'basic', data: {username: 'U', password: 'P'} } this.http(config).then(function(response){ console.log(response); });

To the following hapijs route....

    method: ['POST','OPTIONS'],
    path: '/basic',
    handler: function(req, reply){
        reply('ok good to go');
    },
    config: {
        cors: true
    }

Of course, the google browser starts with request method 'OPTION' but always getting this error "Request header field Content-Type is not allowed by Access-Control-Allow-Headers in preflight response."

What am I doing wrong?

jjtron avatar Nov 23 '15 20:11 jjtron

Same error here.

nebulou5 avatar Dec 01 '15 05:12 nebulou5

+1

sylviefiat avatar Jan 08 '16 22:01 sylviefiat

+1

m0tzy avatar Jan 26 '16 16:01 m0tzy

+1

XanderDwyl avatar Feb 14 '16 14:02 XanderDwyl

If you have an issue, open a new one with full details showing how to reproduce it. Posting +1 is only going to make me less likely to help you out.

hueniverse avatar Feb 20 '16 19:02 hueniverse