CartoDB-SQL-API/lib/api/middlewares/cors.js
Esther Lozano ac8086a8e3
Rename accepted headers for metrics events (#641)
* Rename accepted headers for metrics events
2020-02-18 11:14:06 +01:00

34 lines
900 B
JavaScript

'use strict';
module.exports = function cors (extraHeaders = []) {
return function (req, res, next) {
const headers = [
'X-Requested-With',
'X-Prototype-Version',
'X-CSRF-Token',
'Authorization',
'Carto-Event',
'Carto-Event-Source',
'Carto-Event-Group-Id',
...extraHeaders
];
const exposedHeaders = [
'Carto-Rate-Limit-Limit',
'Carto-Rate-Limit-Remaining',
'Carto-Rate-Limit-Reset',
'Retry-After'
];
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', headers.join(', '));
res.header('Access-Control-Expose-Headers', exposedHeaders.join(', '));
if (req.method === 'OPTIONS') {
return res.send();
}
next();
};
};