Compare commits

..

No commits in common. "a6702f472213acac5946ef3c7c5550f856df1e16" and "99184b9568eba49325bac76ced2b0f0ce32855d2" have entirely different histories.

8 changed files with 36 additions and 77 deletions

View File

@ -2,6 +2,5 @@ module.exports = {
ViewLoader: require('./view_loader'), ViewLoader: require('./view_loader'),
TimeSince: require('./timesince'), TimeSince: require('./timesince'),
HtmlString: require('./htmlstring'), HtmlString: require('./htmlstring'),
GPG: require('./gpg'), GPG: require('./gpg')
Minify: require('./minify')
} }

View File

@ -1,16 +0,0 @@
const minify = require('@node-minify/core');
const cleanCSS = require('@node-minify/clean-css');
/**
*
* @param {string} content
* @returns {string}
*/
async function css(content) {
return await minify({
compressor: cleanCSS,
content
});
}
module.exports = { css };

View File

@ -24,15 +24,20 @@ app.use(express.static('public'));
// 404 // 404
app.use(async (req, res, next) => { app.use(async (req, res, next) => {
try {
if (res.headersSent) return next(); if (res.headersSent) return next();
const Helpers = require('./helpers');
res.status(404); res.status(404).send(await Helpers.ViewLoader.load('error.pug', {
res.template('error.pug', {
error: '404 Not Found', error: '404 Not Found',
message: 'The requested page was not found.' message: 'The requested page was not found.'
}); }))
} catch (err) {
next(err);
}
}) })
// error handler // error handler
app.use(async (err, req, res, next) => { app.use(async (err, req, res, next) => {
console.log(err); console.log(err);
@ -40,11 +45,13 @@ app.use(async (err, req, res, next) => {
return next(err); return next(err);
} }
const Helpers = require('./helpers');
res.status(500); res.status(500);
res.template('error.pug', { res.send(await Helpers.ViewLoader.load('error.pug', {
error: '500 Internal Server Error', error: '500 Internal Server Error',
message: 'An unexpected error happened in the server' message: 'An unexpected error happened in the server'
}); }));
}) })
const server = app.listen(APP_PORT, () => { const server = app.listen(APP_PORT, () => {

View File

@ -1,18 +1,9 @@
const express = require('express'); const express = require('express');
const router = express.Router(); const router = express.Router();
const minify = require('express-minify'); const glob = require('glob');
router.use(require('./template'));
router.use(require('./cookie')); router.use(require('./cookie'));
router.use(require('./session')); router.use(require('./session'));
router.use(require('./session_back')); router.use(require('./session_back'));
router.use(minify({
cache: process.env.APP_DEBUG == true,
uglifyJS: null,
errorHandler: console.error,
css_match: /.css^/,
js_match: /.js^/
}));
module.exports = router; module.exports = router;

View File

@ -1,20 +0,0 @@
const express = require('express');
const router = new express.Router();
const Helpers = require('../helpers');
module.exports = (req, res, next) => {
if (res.template) return next();
res.template = async (file, data) => {
res.send(await Helpers.ViewLoader.load(file, {
...data,
current_route: req.originalUrl,
req,
res,
require
}))
}
return next();
}

View File

@ -12,8 +12,6 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@node-minify/clean-css": "^8.0.5",
"@node-minify/core": "^8.0.5",
"bcrypt": "^5.1.0", "bcrypt": "^5.1.0",
"body-parser": "^1.20.1", "body-parser": "^1.20.1",
"connect-redis": "^6.1.3", "connect-redis": "^6.1.3",
@ -23,7 +21,6 @@
"dotenv": "^16.0.3", "dotenv": "^16.0.3",
"express": "^4.18.2", "express": "^4.18.2",
"express-async-handler": "^1.2.0", "express-async-handler": "^1.2.0",
"express-minify": "^1.0.0",
"express-session": "^1.17.3", "express-session": "^1.17.3",
"glob": "^8.1.0", "glob": "^8.1.0",
"gulp": "^4.0.2", "gulp": "^4.0.2",

View File

@ -13,7 +13,8 @@ async function handler(req, res) {
limit: 5 limit: 5
}); });
await res.template( res.send(
await Helpers.ViewLoader.load(
'main.pug', 'main.pug',
{ {
current_route: '/', current_route: '/',
@ -26,6 +27,7 @@ async function handler(req, res) {
url: req.protocol + '://' + req.get('host') + req.originalUrl url: req.protocol + '://' + req.get('host') + req.originalUrl
} }
} }
)
); );
return; return;
} }

View File

@ -18,8 +18,7 @@ require('dotenv').config({
}); });
// load debug // load debug
if (process.env.APP_DEBUG == 'true') { if (process.env.APP_DEBUG) {
process.env.APP_DEBUG = true;
process.env.DEBUG = '*/*'; process.env.DEBUG = '*/*';
} }