Index page almost OK. Now work on variant page (main hall...)
[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
1d184b4c
BA
9var app = express();
10
11app.use(favicon(path.join(__dirname, "public", "images", "favicon", "favicon.ico")));
12
13if (app.get('env') === 'development')
14{
15 // Full logging in development mode
16 app.use(logger('dev'));
17}
18else
19{
92342261
BA
20 // http://dev.rdybarra.com/2016/06/23/Production-Logging-With-Morgan-In-Express/
21 app.set('trust proxy', true);
1d184b4c
BA
22 // In prod, only log error responses (https://github.com/expressjs/morgan)
23 app.use(logger('combined', {
24 skip: function (req, res) { return res.statusCode < 400 }
25 }));
26}
27
fb1ecbdf
BA
28// Allow layout.pug to select the right vue file:
29app.locals.development = app.get('env') === 'development';
30
1d184b4c
BA
31// view engine setup
32app.set('views', path.join(__dirname, 'views'));
33app.set('view engine', 'pug');
34
35app.use(express.json());
36app.use(express.urlencoded({ extended: false }));
37app.use(cookieParser());
38app.use(sassMiddleware({
39 src: path.join(__dirname, 'public'),
40 dest: path.join(__dirname, 'public'),
41 indentedSyntax: true, // true = .sass and false = .scss
42 sourceMap: true
43}));
44app.use(express.static(path.join(__dirname, 'public')));
45
298c42e6
BA
46const routes = require(path.join(__dirname, "routes", "all"));
47app.use('/', routes);
1d184b4c
BA
48
49// catch 404 and forward to error handler
50app.use(function(req, res, next) {
51 next(createError(404));
52});
53
54// error handler
55app.use(function(err, req, res, next) {
56 // set locals, only providing error in development
57 res.locals.message = err.message;
58 res.locals.error = req.app.get('env') === 'development' ? err : {};
59 // render the error page
60 res.status(err.status || 500);
61 res.render('error');
62});
63
64module.exports = app;