How to use the corser.simpleResponseHeaders function in corser

To help you get started, we’ve selected a few corser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github deployd / deployd / lib / util / http.js View on Github external
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;

corser

A highly configurable, middleware compatible implementation of CORS.

MIT
Latest version published 8 years ago

Package Health Score

67 / 100
Full package analysis