Last active
January 15, 2019 11:41
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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