I have an express application with many routes:
app.get('foo/bar', function(res, res, next) { ... });
app.post('foo/bar', function(res, res, next) { ... });
app.get('another/one/path', function(res, res, next) { ... }));
And I need to send cross domain AJAX requests to this application. So, I need to send correct Access-Control-Allow-Methods on OPTIONS requests. For example, if the request is OPTIONS 'foo/bar'
, then the Access-Control-Allow-Methods header should be equal GET,POST
.
I see that if I send OPTIONS request in Express framework I already get a correct list of methods in response body. For example if I I send OPTIONS 'foo/bar'
I get a response with body GET,POST
. Now, I want to send GET,POST
in Access-Control-Allow-Methods
header too. I'm trying to find an easy solution to do this. I don't want to add an options routes, because I already have more than 200 routes in the application.