hapijs / glue

Server composer for hapi.js
Other
245 stars 62 forks source link

No CORS options response when vhost is configured #38

Closed robinvdvleuten closed 8 years ago

robinvdvleuten commented 8 years ago

If I configure a vhost for routes in a plugin, the CORS options requests results in a 404 response.

It can be reproduced with the following example;

var Glue = require('glue'),
    Hapi = require('hapi');
    Config = require('./lib/config');

var manifest = {
    connections: [
        {
            port: Config.port
        }
    ],
    plugins: {
        './web': [{
            routes: {
                vhost: 'example.com'
            }
        }],
        './plugins/rethink': Config.rethink,
        'good': Config.monitor
    }
};

var options = {
    relativeTo: __dirname + '/lib'
};

Glue.compose(manifest, options, function (err, server) {

    if (err) {
        throw err;
    }

    server.start(function () {

        console.log('Hapi days!');
    });
});

If I comment out the vhost option, the CORS response is returned as expected.

mtharrison commented 8 years ago

Please try to provide the full code that we can run ourselves to confirm the issue. Otherwise we have to make guesses about everything you don't include and they could be incorrect guesses.

Here's a full example of the above that can be run: https://gist.github.com/mtharrison/eb771b4a2bace5a639c9

The above example doesn't give the 404 that you're reporting.

mtharrison commented 8 years ago

I did notice if you use a port other than 80 (such as 4000), the CORS OPTIONS request will 404. This is because the following check:

https://github.com/hapijs/call/blob/master/lib/index.js#L92

It will compare example.com (the vhost setting) with example.com:4000 (the host header). It's not possible however to set the vhost option to include a port number. I'm not sure if this is a bug or not though. /cc @hueniverse

robinvdvleuten commented 8 years ago

@mtharrison ok the issue was indeed the port number not being port 80. But it looks like a bug in the if-statement then.

hueniverse commented 8 years ago

Sounds like a bug in how the options handler sets vhost.

mtharrison commented 8 years ago

I think this issue should be migrated to hapi as that's where the issue seems to lie.

mtharrison commented 8 years ago

https://github.com/hapijs/hapi/issues/2930

lock[bot] commented 4 years ago

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.