Skip to content

Instantly share code, notes, and snippets.

@donjosef donjosef/app.js
Created Sep 24, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.