Slight improve in bug report instructions
[vchess.git] / app.js
CommitLineData
1d184b4c
BA
1var createError = require('http-errors');
2var express = require('express');
3var path = require('path');
4var cookieParser = require('cookie-parser');
5var logger = require('morgan');
6var sassMiddleware = require('node-sass-middleware');
7var favicon = require('serve-favicon');
8
9var router = require('./routes/all');
10
11var app = express();
12
13app.use(favicon(path.join(__dirname, "public", "images", "favicon", "favicon.ico")));
14
15if (app.get('env') === 'development')
16{
17 // Full logging in development mode
18 app.use(logger('dev'));
19}
20else
21{
22 app.set('trust proxy', true); //http://dev.rdybarra.com/2016/06/23/Production-Logging-With-Morgan-In-Express/
23 // In prod, only log error responses (https://github.com/expressjs/morgan)
24 app.use(logger('combined', {
25 skip: function (req, res) { return res.statusCode < 400 }
26 }));
27}
28
29// view engine setup
30app.set('views', path.join(__dirname, 'views'));
31app.set('view engine', 'pug');
32
33app.use(express.json());
34app.use(express.urlencoded({ extended: false }));
35app.use(cookieParser());
36app.use(sassMiddleware({
37 src: path.join(__dirname, 'public'),
38 dest: path.join(__dirname, 'public'),
39 indentedSyntax: true, // true = .sass and false = .scss
40 sourceMap: true
41}));
42app.use(express.static(path.join(__dirname, 'public')));
43
44app.use('/', router);
45
46// catch 404 and forward to error handler
47app.use(function(req, res, next) {
48 next(createError(404));
49});
50
51// error handler
52app.use(function(err, req, res, next) {
53 // set locals, only providing error in development
54 res.locals.message = err.message;
55 res.locals.error = req.app.get('env') === 'development' ? err : {};
56 // render the error page
57 res.status(err.status || 500);
58 res.render('error');
59});
60
61module.exports = app;