add previous url

This commit is contained in:
b1ek 2023-02-19 12:32:25 +10:00
parent 843700e27c
commit 60d4a477bd
Signed by: blek
GPG Key ID: 14546221E3595D0C
2 changed files with 35 additions and 0 deletions

19
middleware/index.js Normal file
View File

@ -0,0 +1,19 @@
const express = require('express');
const router = express.Router();
const glob = require('glob');
glob(__dirname + "/**/*.js", {}, (er, data) => {
if (er) {
console.error(er);
process.exit(-1);
}
data
.filter(file => {
return !file.endsWith('index.js')
})
.forEach(file => {
require(file)(router);
});
});
module.exports = router;

View File

@ -0,0 +1,16 @@
async function handler(req, res, next) {
// TODO:
// Log only non-automatical requests
// In other words, ignore requests like favicon.ico
if (!req.accepts('html') && !req.accepts('*')) {
next();
return;
}
req.session.prev = req.originalUrl;
req.session.save();
next();
}
module.exports = (router) => {
router.use(handler);
}