Created
June 29, 2019 16:03
-
-
Save BetterProgramming/d2610251b929bb2093a90f8c45f0221f to your computer and use it in GitHub Desktop.
This file contains 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
var express = require('express') | |
,cors = require('cors') | |
, app = express(); | |
//app.user(bodyParser.json()); | |
// after the code that uses bodyParser and other cool stuff | |
var originsWhitelist = [ | |
'http://localhost:4200', //this is my front-end url for development | |
'http://www.myproductionurl.com' | |
]; | |
var corsOptions = { | |
origin: function(origin, callback){ | |
var isWhitelisted = originsWhitelist.indexOf(origin) !== -1; | |
callback(null, isWhitelisted); | |
}, | |
credentials:true | |
} | |
//here is the magic | |
app.use(cors(corsOptions)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment