Last active
August 5, 2020 02:01
-
-
Save pravin772/d96b9572c9b2e4080450f7234b9ac22e to your computer and use it in GitHub Desktop.
Node.js Express server
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 cors = require('cors') | |
const bodyParser = require('body-parser'); | |
const app = express() | |
app.use(cors()) | |
app.use(express.json()) | |
app.use(bodyParser.json()) | |
app.use(function (req, res, next) { | |
res.header("Access-Control-Allow-Origin", "*") // update to match the domain you will make the request from | |
res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE') // If needed | |
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept") | |
res.header('Access-Control-Allow-Credentials', true) | |
next() | |
}); | |
app.use('/protected/', require('./routes/index')) | |
app.listen('5000', () => console.log('Server started and listening on PORT 5000')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment