Compare commits
No commits in common. "a6702f472213acac5946ef3c7c5550f856df1e16" and "99184b9568eba49325bac76ced2b0f0ce32855d2" have entirely different histories.
a6702f4722
...
99184b9568
|
@ -1,7 +1,6 @@
|
||||||
module.exports = {
|
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')
|
|
||||||
}
|
}
|
|
@ -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 };
|
|
25
index.js
25
index.js
|
@ -24,15 +24,20 @@ app.use(express.static('public'));
|
||||||
|
|
||||||
// 404
|
// 404
|
||||||
app.use(async (req, res, next) => {
|
app.use(async (req, res, next) => {
|
||||||
if (res.headersSent) return next();
|
try {
|
||||||
|
if (res.headersSent) return next();
|
||||||
res.status(404);
|
const Helpers = require('./helpers');
|
||||||
res.template('error.pug', {
|
res.status(404).send(await Helpers.ViewLoader.load('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, () => {
|
||||||
|
|
|
@ -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;
|
|
@ -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();
|
|
||||||
}
|
|
|
@ -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",
|
||||||
|
|
|
@ -13,19 +13,21 @@ async function handler(req, res) {
|
||||||
limit: 5
|
limit: 5
|
||||||
});
|
});
|
||||||
|
|
||||||
await res.template(
|
res.send(
|
||||||
'main.pug',
|
await Helpers.ViewLoader.load(
|
||||||
{
|
'main.pug',
|
||||||
current_route: '/',
|
{
|
||||||
gb_entries,
|
current_route: '/',
|
||||||
articles,
|
gb_entries,
|
||||||
og: {
|
articles,
|
||||||
title: 'blek! Site',
|
og: {
|
||||||
type: 'website',
|
title: 'blek! Site',
|
||||||
image: req.protocol + '://' + req.get('host') + '/content/transylveonia.jpg',
|
type: 'website',
|
||||||
url: req.protocol + '://' + req.get('host') + req.originalUrl
|
image: req.protocol + '://' + req.get('host') + '/content/transylveonia.jpg',
|
||||||
|
url: req.protocol + '://' + req.get('host') + req.originalUrl
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 = '*/*';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue