Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

add HTTP OPTIONS handler in CORS example #1398

Closed
bodokaiser opened this Issue · 1 comment

2 participants

@bodokaiser

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 in 4283f38
@tj
tj commented

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
Something went wrong with that request. Please try again.