Created
July 13, 2019 17:42
-
-
Save matthewoestreich/26cdb8c357e5be3a292cad0806d85ad3 to your computer and use it in GitHub Desktop.
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
// CORS middleware function (this will allow any host to be able to send requests) | |
function allowCors(req, res, next) { | |
res.header("Access-Control-Allow-Origin", "*"); | |
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); | |
next(); | |
} | |
// This is how you tie it into your app - | |
// NOTE: This opens up every single route - this is merely an example | |
const express = require('express'); | |
const app = express(); | |
// other stuff here | |
// add CORS middleware | |
///// SET UP CORS ////// | |
app.use(allowCors); //// | |
//////////////////////// | |
// more stuff here | |
let listenOn = 5000; | |
app.listen(listenOn, () => { | |
console.log(`App started on port ${listenOn}`) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment