handle async safely

This commit is contained in:
b1ek 2023-03-12 12:28:05 +10:00
parent 948776af62
commit 289e93cfca
Signed by: blek
GPG Key ID: 14546221E3595D0C
3 changed files with 13 additions and 14 deletions

View File

@ -1,13 +1,12 @@
const Helpers = require('../helpers');
const Sequelize = require('../models');
const html_escape = require('html-escaper');
const xml = require('xml');
const handler = require('express-async-handler');
const send_error = async (res, error) => {
return res.redirect('/guestbook?error=' + encodeURIComponent(error));
};
async function handler(req, res, next) {
async function guestbook(req, res, next) {
try {
const errors = req.query.error;
@ -179,8 +178,8 @@ async function rss(req, res) {
}
module.exports = (router) => {
router.get('/guestbook', handler);
router.post('/guestbook/submit', submit);
router.get('/guestbook/del/:id', del);
router.get('/guestbook.rss', rss);
router.get('/guestbook', handler(guestbook));
router.post('/guestbook/submit', handler(submit));
router.get('/guestbook/del/:id', handler(del));
router.get('/guestbook.rss', handler(rss));
}

View File

@ -1,7 +1,7 @@
const Helpers = require('../helpers');
const Sequelize = require('../models');
const handler = require('express-async-handler');
async function handler(req, res) {
async function index(req, res) {
let gb_entries = await Sequelize.Guestbook.findAll({
limit: 5,
@ -31,6 +31,6 @@ async function handler(req, res) {
}
module.exports = (router) => {
router.get('/', handler);
router.get('/', handler(index));
router.get('/sources', (req, res) => {res.redirect('https://git.blek.codes/blek/homepage.js')});
}

View File

@ -1,6 +1,6 @@
const Helpers = require('../helpers');
const handler = require('express-async-handler');
async function handler(req, res) {
async function project(req, res) {
res.template(
'project.pug',
{
@ -34,6 +34,6 @@ async function viewer(req, res) {
}
module.exports = (router) => {
router.get('/project', handler);
router.get('/project/:id', viewer);
router.get('/project', handler(project));
router.get('/project/:id', handler(viewer));
}