Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bodyParser from 'body-parser';
- import cookieParser from 'cookie-parser';
- import Debug from 'debug';
- import express from 'express';
- import logger from 'morgan';
- import './models/db';
- import index from './routes/index';
- const app = express();
- const debug = Debug('agenda-server:app');
- // uncomment after placing your favicon in /public
- app.use(logger('dev'));
- app.use(bodyParser.json());
- app.use(bodyParser.urlencoded({
- extended: false
- }));
- app.use(cookieParser());
- app.use(function (req, res, next) {
- res.header("Access-Control-Allow-Origin", "*");
- res.header("Access-Control-Allow-Methods", "GET, PUT, POST, DELETE");
- res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
- next();
- });
- app.use('/', index);
- // catch 404 and forward to error handler
- app.use((req, res, next) => {
- const err = new Error('Not Found');
- err.status = 404;
- next(err);
- });
- // error handler
- /* eslint no-unused-vars: 0 */
- app.use((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 : {};
- // render the error page
- res.status(err.status || 500);
- res.json(err);
- });
- // Handle uncaughtException
- process.on('uncaughtException', (err) => {
- debug('Caught exception: %j', err);
- process.exit(1);
- });
- export default app;
Add Comment
Please, Sign In to add comment