Skip to content

Instantly share code, notes, and snippets.

@mirajehossain
Created July 5, 2018 16:39
Show Gist options
  • Save mirajehossain/7d88f79938befd50f7354e556f942a67 to your computer and use it in GitHub Desktop.
Save mirajehossain/7d88f79938befd50f7354e556f942a67 to your computer and use it in GitHub Desktop.
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