Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add HTTP OPTIONS handler in CORS example #1398

Closed
bodokaiser opened this issue Nov 4, 2012 · 1 comment
Closed

add HTTP OPTIONS handler in CORS example #1398

bodokaiser opened this issue Nov 4, 2012 · 1 comment

Comments

@bodokaiser
Copy link

Hello,

when using CORS the browser tries to do a OPTIONS request to check cross domain policy. This is not handled from express itself and it would be helpful if you add it to you example.

app.all('*', function(req, res, next) {
    res.header('Access-Control-Allow-Origin', 'http://node.enabre.com:3000');
    res.header('Access-Control-Allow-Methods', 'HEAD, GET, POST, PUT, DELETE, OPTIONS');
    res.header('Access-Control-Allow-Headers', 'Content-Type, X-Requested-With, Origin, Accept');
    res.header('Access-Control-Allow-Credentials', 'true');

    if (req.method.toLowerCase() === 'options') {
        res.send(200);
    } else {
        next();
    }
});

source: http://stackoverflow.com/questions/13218174/cors-put-not-found-with-jquery-ajax

Regards, bodo

@tj tj closed this as completed in 4283f38 Nov 4, 2012
@tj
Copy link
Member

tj commented Nov 4, 2012

thanks! oddly it does work fine when 404ing for me in chrome at least but certainly not reason to next() there anyway

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants