Advance on Spanish translation (still 13 rules to translate)
[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{
92342261
BA
22 // http://dev.rdybarra.com/2016/06/23/Production-Logging-With-Morgan-In-Express/
23 app.set('trust proxy', true);
1d184b4c
BA
24 // In prod, only log error responses (https://github.com/expressjs/morgan)
25 app.use(logger('combined', {
26 skip: function (req, res) { return res.statusCode < 400 }
27 }));
28}
29
fb1ecbdf
BA
30// Allow layout.pug to select the right vue file:
31app.locals.development = app.get('env') === 'development';
32
1d184b4c
BA
33// view engine setup
34app.set('views', path.join(__dirname, 'views'));
35app.set('view engine', 'pug');
36
37app.use(express.json());
38app.use(express.urlencoded({ extended: false }));
39app.use(cookieParser());
40app.use(sassMiddleware({
41 src: path.join(__dirname, 'public'),
42 dest: path.join(__dirname, 'public'),
43 indentedSyntax: true, // true = .sass and false = .scss
44 sourceMap: true
45}));
46app.use(express.static(path.join(__dirname, 'public')));
47
48app.use('/', router);
49
50// catch 404 and forward to error handler
51app.use(function(req, res, next) {
52 next(createError(404));
53});
54
55// error handler
56app.use(function(err, req, res, next) {
57 // set locals, only providing error in development
58 res.locals.message = err.message;
59 res.locals.error = req.app.get('env') === 'development' ? err : {};
60 // render the error page
61 res.status(err.status || 500);
62 res.render('error');
63});
64
65module.exports = app;