33 lines
861 B
JavaScript
33 lines
861 B
JavaScript
const express = require('express');
|
|
const path = require('path');
|
|
require('dotenv').config();
|
|
env = process.env;
|
|
|
|
const app = express();
|
|
|
|
app.use(express.json());
|
|
app.use(express.urlencoded({ extended: false }));
|
|
app.use(require('cookie-parser')());
|
|
app.use(express.static(path.join(__dirname, 'static')));
|
|
|
|
app.use('/', require('./routes/index.js'));
|
|
|
|
// catch 404 and forward to error handler
|
|
app.use(function(req, res, next) {
|
|
res.status(404);
|
|
res.end('<h1>404 Not Found</h1>');
|
|
});
|
|
|
|
// 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 : {};
|
|
|
|
console.log(err);
|
|
// render the error page
|
|
res.status(err.status || 500);
|
|
res.end('<h1>error</h1>');
|
|
});
|
|
|
|
module.exports = app; |