Skip to content

Instantly share code, notes, and snippets.

@donjosef
Created September 24, 2019 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donjosef/2c70ffa922237228eeb6c72c84d09393 to your computer and use it in GitHub Desktop.
Save donjosef/2c70ffa922237228eeb6c72c84d09393 to your computer and use it in GitHub Desktop.
Initialize settings for express
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