Created
January 17, 2019 21:19
-
-
Save bmorrisondev/266d0656f87437c34618ed01a41a3659 to your computer and use it in GitHub Desktop.
A simple shell of an Express app
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
if(process.env.ENVIRONMENT != "PROD") { | |
require('dotenv').config() | |
} | |
const express = require('express'); | |
const app = express(); | |
const bodyParser = require('body-parser'); | |
const morgan = require('morgan') | |
const routes = require('./routes') | |
app.use(bodyParser.urlencoded({ extended: true })) | |
app.use(bodyParser.json()) | |
app.use(morgan('tiny')) | |
app.use((req, res, next) => { | |
res.header("Access-Control-Allow-Origin", "*") | |
res.header("Access-Control-Allow-Methods", "GET, POST, PUT, OPTIONS, DELETE") | |
res.header("Access-Control-Allow-Headers", "Content-Type, Authorization") | |
// Approve response to pre-flight requests | |
if('OPTIONS' == req.method) { | |
res.send(200); | |
} else { | |
next() | |
} | |
}) | |
app.use('/', routes) | |
const port = 3000 | |
app.listen(port) | |
console.log(`listening on http://localhost:${port}`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment