Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports.setup = function(options, req, res, next) {
var remoteHost = req.headers.origin
, corsOpts = {supportsCredentials: true, methods: ALLOWED_METHODS, maxAge: 300};
if(remoteHost) {
corsOpts.origins = options.origins;
} else {
corsOpts.supportsCredentials = false;
}
corsOpts.responseHeaders = corser.simpleResponseHeaders.concat(["X-Session-Token", "X-Session-Invalidated"]).concat(options.allowedResponseHeaders || []);
corsOpts.requestHeaders = corser.simpleRequestHeaders.concat(["X-Requested-With", "Authorization"]).concat(options.allowedRequestHeaders || []);
if (options.allowCorsRootRequests) {
corsOpts.requestHeaders.push("dpd-ssh-key");
}
var handler = corser.create(corsOpts);
handler(req, res, function () {
req.cookies = res.cookies = new Cookies(req, res);
if(~req.url.indexOf('?')) {
try {
req.query = parseQuery(req.url);
var m = req.query._method;
if ( m ) {
req.originalMethod = req.method;