pastel.codes/app.js

49 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-06-17 22:34:29 +01:00
var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var sassMiddleware = require('node-sass-middleware');
var indexRouter = require('./routes/index');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(sassMiddleware({
src: path.join(__dirname, 'public'),
dest: path.join(__dirname, 'public'),
indentedSyntax: true, // true = .sass and false = .scss
sourceMap: true
2020-06-17 22:34:29 +01:00
}));
app.use(express.static(path.join(__dirname, 'public')));
2020-06-22 17:44:15 +01:00
app.disable('x-powered-by');
2020-06-17 22:34:29 +01:00
app.use('/', indexRouter);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
2020-06-22 17:48:10 +01:00
next(createError(404));
2020-06-17 22:34:29 +01:00
});
// 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 : {};
2020-06-17 22:34:29 +01:00
// render the error page
res.status(err.status || 500);
2020-06-22 17:57:35 +01:00
res.render('error', { title: 'Error', description: "Error" });
2020-06-17 22:34:29 +01:00
});
module.exports = app;