You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
2.6 KiB
JavaScript
102 lines
2.6 KiB
JavaScript
let config = require("./libs/configuration");
|
|
let express = require('express');
|
|
let createError = require("http-errors");
|
|
let path = require('path');
|
|
let cookieParser = require('cookie-parser');
|
|
//let lessMiddleware = require('less-middleware');
|
|
let logger = require('morgan');
|
|
let expressLayout = require('express-layout');
|
|
let hbs = require('hbs');
|
|
//let expressValidator = require('express-validator');
|
|
//let expressSession = require('express-session');
|
|
//let sessionMySQL = require("connect-mysql")(expressSession);
|
|
let compression = require("compression");
|
|
//let expressMinify = require('express-minify');
|
|
//let expressMinifyHtml = require('express-minify-html');
|
|
|
|
let app = express();
|
|
|
|
// Configure Views
|
|
app.set('views', path.join(__dirname, 'views'));
|
|
app.engine('hbs', hbs.__express);
|
|
app.set('view engine', 'hbs');
|
|
app.set('layouts', './views');
|
|
app.set('layout', 'html');
|
|
app.set('trust proxy', 'loopback');
|
|
|
|
app.use(logger('dev'));
|
|
app.use(express.json());
|
|
app.use(express.urlencoded({extended: false}));
|
|
app.use(expressLayout());
|
|
//app.use(expressValidator());
|
|
/*app.use(expressSession({
|
|
//store: require("./libs/SessionStorage"),
|
|
secret: config.session.secret,
|
|
saveUninitialized: false,
|
|
resave: true,
|
|
cookie: {
|
|
secure: false,
|
|
httpOnly: true,
|
|
maxAge: config.session.cookieMaxAge,
|
|
}
|
|
}));*/
|
|
app.use(cookieParser());
|
|
app.use(compression());
|
|
/*
|
|
app.use(expressMinify({
|
|
cache: __dirname + "/cache",
|
|
jsMatch: /javascript/,
|
|
cssMatch: /css/,
|
|
jsonMatch: /json/,
|
|
lessMatch: /less/,
|
|
}));
|
|
*/
|
|
/*
|
|
app.use(expressMinifyHtml({
|
|
override: true,
|
|
exception_url: false,
|
|
htmlMinifier: {
|
|
removeComments: true,
|
|
collapseWhitespace: true,
|
|
collapseBooleanAttributes: true,
|
|
removeAttributeQuotes: true,
|
|
removeEmptyAttributes: true,
|
|
minifyJS: true,
|
|
},
|
|
}));
|
|
*/
|
|
//app.use(lessMiddleware(path.join(__dirname, 'public')));
|
|
app.use(express.static(path.join(__dirname, 'static'), {
|
|
dotfiles: "ignore",
|
|
index: "index.htm",
|
|
redirect: false
|
|
}));
|
|
|
|
/* Routes */
|
|
|
|
function route(path, route) {
|
|
app.use(path, require('./routes/' + route));
|
|
}
|
|
|
|
route("/ssh", "ssh");
|
|
|
|
// 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');
|
|
});
|
|
|
|
require("./prepare")(app);
|
|
|
|
module.exports = app;
|