Created
December 27, 2018 16:08
-
-
Save JBreit/5310233faa0f66ea7f79c2a89ef35116 to your computer and use it in GitHub Desktop.
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 cookieParser = require('cookie-parser'); | |
const favicon = require('serve-favicon'); | |
const morgan = require('morgan'); | |
const methodOverride = require('method-override'); | |
const path = require('path'); | |
const app = express(); | |
const { HOST = '127.0.0.1', PORT = 8080 } = process.env; | |
app.use(favicon(path.join('./../imco/dist', 'assets', 'img', 'favicon.ico'))); | |
app.use(bodyParser.urlencoded({ extended: true })); | |
app.use(bodyParser.json()); | |
app.use(bodyParser.json({ type: 'application/vnd.api+json' })); | |
app.use(cookieParser()); | |
app.use(methodOverride('X-HTTP-Override')); | |
app.use(express.static('./../imco/dist')); | |
app.use(morgan('dev')); | |
app.use((req, res, next) => { | |
const err = new Error('Not Found'); | |
err.status = 404; | |
err.url = req.originalUrl; | |
next(err); | |
}); | |
app.use((err, req, res, next) => { // eslint-disable-line no-unused-vars | |
res.status(err.status || 500).json({ | |
message: err.message, | |
url: req.originalUrl, | |
error: err, | |
}); | |
}); | |
app.listen(PORT, HOST, () => { process.stdout.write(`Server running at http://${HOST}:${PORT}/\n`); }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment