Skip to content

Instantly share code, notes, and snippets.

@pablocattaneo
Last active January 15, 2019 11:41
Show Gist options
  • Save pablocattaneo/1ebc798e019c4962129855eff2898ba8 to your computer and use it in GitHub Desktop.
Save pablocattaneo/1ebc798e019c4962129855eff2898ba8 to your computer and use it in GitHub Desktop.
How to solve CORS problems in Express? #Express #node #CORS Source: https://www.udemy.com/nodejs-the-complete-guide/learn/v4/t/lecture/12087628?start=15
// In the entry file often index.js or app.js
const express = require('express')
const app = express()
app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', '*') // The second parámeter could be a list of domains
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE')
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization')
next()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment