Created
July 5, 2018 16:39
-
-
Save mirajehossain/7d88f79938befd50f7354e556f942a67 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 logger = require('morgan'); | |
const cookieParser = require('cookie-parser'); | |
const bodyParser = require('body-parser'); | |
const multer = require('multer'); | |
const index = require('./routes/index'); | |
const app = express(); | |
app.use(function(req, res, next) { | |
res.setHeader('Access-Control-Allow-Origin', '*'); | |
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS'); | |
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type, Authorization'); | |
next(); | |
}); | |
// uncomment after placing your favicon in /public | |
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico'))); | |
app.use(logger('dev')); | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded({ extended: false })); | |
app.use(cookieParser()); | |
app.use(multer().single()); | |
app.use('/', index); | |
// catch 404 and forward to error handler | |
app.use(function(req, res, next) { | |
const err = new Error('Not Found'); | |
err.status = 404; | |
next(err); | |
}); | |
// error handler | |
app.use(function(err, req, res, next) { | |
// set locals, only providing error in development | |
res.locals.message = err.message; | |
res.locals.error = req.app.get('env') === 'development' ? err : {}; | |
}); | |
module.exports = app; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment