2021-01-27 23:36:51 +01:00
const createError = require ( 'http-errors' ) ;
const express = require ( 'express' ) ;
const path = require ( 'path' ) ;
const cookieParser = require ( 'cookie-parser' ) ;
2021-01-28 01:30:55 +01:00
const bodyParser = require ( 'body-parser' )
2021-01-27 23:36:51 +01:00
const logger = require ( './config/winston' ) ;
2021-12-06 18:13:15 +01:00
//const sassMiddleware = require('node-sass-middleware');
2021-01-27 23:36:51 +01:00
const expressWinston = require ( 'express-winston' ) ;
2021-01-30 20:33:06 +01:00
const flash = require ( 'connect-flash' ) ;
2021-01-27 23:36:51 +01:00
const i18n = require ( 'i18n' ) ;
2021-01-30 20:33:06 +01:00
const session = require ( 'express-session' ) ;
2021-01-27 23:36:51 +01:00
const indexRouter = require ( './routes/index' ) ;
2021-01-28 01:30:55 +01:00
const loginRouter = require ( './routes/login' ) ;
2021-01-30 20:33:06 +01:00
const presetManagerRouter = require ( './routes/preset-manager' ) ;
2021-01-28 01:30:55 +01:00
const passport = require ( './config/passport' ) ;
2021-01-27 23:36:51 +01:00
const app = express ( ) ;
// view engine setup
app . set ( 'views' , path . join ( _ _dirname , 'views' ) ) ;
app . set ( 'view engine' , 'ejs' ) ;
i18n . configure ( {
// setup some locales - other locales default to en silently
locales : [ 'en' , 'fr' ] ,
// where to store json files - defaults to './locales'
directory : _ _dirname + '/locales'
} ) ;
// Logger
app . use ( expressWinston . logger ( {
winstonInstance : logger ,
meta : true , // optional: control whether you want to log the meta data about the request (default to true)
expressFormat : true , // Use the default Express/morgan request formatting. Enabling this will override any msg if true. Will only output colors with colorize set to true
colorize : true , // Color the text and status code, using the Express/morgan color palette (text: gray, status: default green, 3XX cyan, 4XX yellow, 5XX red).
level : function ( req , res ) {
if ( res . statusCode < 500 )
return "debug" ;
return "warn" ;
}
} ) ) ;
app . use ( express . json ( ) ) ;
app . use ( express . urlencoded ( { extended : false } ) ) ;
2021-01-30 20:33:06 +01:00
app . use ( session ( { secret : 'keyboard cat' , resave : false , saveUninitialized : false } ) ) ;
2021-01-27 23:36:51 +01:00
app . use ( cookieParser ( ) ) ;
2021-01-28 01:30:55 +01:00
app . use ( bodyParser . urlencoded ( { extended : true } ) ) ;
// app.use(sassMiddleware({
// src: path.join(__dirname, 'public'),
// dest: path.join(__dirname, 'public'),
// indentedSyntax: false, // true = .sass and false = .scss
// sourceMap: true,
// debug: false,
// response: false,
// log: function (severity, key, value) { logger.log(severity, `node-sass-middleware ${key} : ${value}`); }
//
// }));
2021-01-27 23:36:51 +01:00
app . use ( express . static ( path . join ( _ _dirname , 'public' ) ) ) ;
app . use ( i18n . init )
2021-01-28 01:30:55 +01:00
app . use ( passport . initialize ( ) ) ;
app . use ( passport . session ( ) ) ;
2021-01-30 20:33:06 +01:00
app . use ( flash ( ) ) ;
2021-01-28 01:30:55 +01:00
2021-01-27 23:36:51 +01:00
app . use ( '/' , indexRouter ) ;
2021-01-28 01:30:55 +01:00
app . use ( '/' , loginRouter ) ;
2021-01-30 20:33:06 +01:00
app . use ( '/' , presetManagerRouter ) ;
2021-01-27 23:36:51 +01:00
// Boootstrap JS Files
app . use ( '/js/bootstrap.min.js' , express . static ( path . join ( _ _dirname , '/node_modules/bootstrap/dist/js/bootstrap.min.js' ) ) )
2021-01-30 20:33:06 +01:00
// Fontawesome Files
app . use ( '/css/fa-all.min.css' , express . static ( path . join ( _ _dirname , '/node_modules/@fortawesome/fontawesome-free/css/all.min.css' ) ) )
app . use ( '/webfonts/' , express . static ( path . join ( _ _dirname , '/node_modules/@fortawesome/fontawesome-free/webfonts' ) ) )
2021-01-27 23:36:51 +01:00
// catch 404 and forward to error handler
app . use ( function ( req , res , next ) {
next ( createError ( 404 ) ) ;
} ) ;
// 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 : { } ;
// render the error page
res . status ( err . status || 500 ) ;
res . render ( 'error' ) ;
} ) ;
module . exports = app ;