Created
September 24, 2019 17:15
-
-
Save donjosef/2c70ffa922237228eeb6c72c84d09393 to your computer and use it in GitHub Desktop.
Initialize settings for express
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
const express = require('express'); | |
const bodyParser = require('body-parser'); | |
const app = express(); | |
//middleware to allow the parsing of the incoming request body | |
app.use(bodyParser.json()); | |
//Middleware to set response headers to handle CORS errors | |
app.use((req, res, next) => { | |
res.set({ | |
'Access-Control-Allow-Origin': '*', | |
'Access-Control-Allow-Methods': 'DELETE,GET,PATCH,POST,PUT', | |
'Access-Control-Allow-Headers': 'Content-Type,Authorization' | |
}); | |
next(); //pass control onto the next middleware | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment