Skip to content

Instantly share code, notes, and snippets.

@goldhand
Created November 8, 2018 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goldhand/e3132b2029fb29e08b4248b592c13ed9 to your computer and use it in GitHub Desktop.
Save goldhand/e3132b2029fb29e08b4248b592c13ed9 to your computer and use it in GitHub Desktop.
const accessCors = res => {
// Website you wish to allow to connect
res.setHeader('Access-Control-Allow-Origin', '*');
// Request methods you wish to allow
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
// Request headers you wish to allow
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
// Set to true if you need the website to include cookies in the requests sent
// to the API (e.g. in case you use sessions)
res.setHeader('Access-Control-Allow-Credentials', true);
};
module.exports = accessCors;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment