mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
refactor: get rid of util.promisify on async function
This commit is contained in:
@@ -9,7 +9,7 @@ const plugins = require('../plugins');
|
|||||||
const middleware = require('../middleware');
|
const middleware = require('../middleware');
|
||||||
const helpers = require('../middleware/helpers');
|
const helpers = require('../middleware/helpers');
|
||||||
|
|
||||||
exports.handle404 = function handle404(req, res) {
|
exports.handle404 = helpers.try(async (req, res) => {
|
||||||
const relativePath = nconf.get('relative_path');
|
const relativePath = nconf.get('relative_path');
|
||||||
const isClientScript = new RegExp(`^${relativePath}\\/assets\\/src\\/.+\\.js(\\?v=\\w+)?$`);
|
const isClientScript = new RegExp(`^${relativePath}\\/assets\\/src\\/.+\\.js(\\?v=\\w+)?$`);
|
||||||
|
|
||||||
@@ -38,13 +38,13 @@ exports.handle404 = function handle404(req, res) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
meta.errors.log404(req.path.replace(/^\/api/, '') || '');
|
meta.errors.log404(req.path.replace(/^\/api/, '') || '');
|
||||||
exports.send404(req, res);
|
await exports.send404(req, res);
|
||||||
} else {
|
} else {
|
||||||
res.status(404).type('txt').send('Not found');
|
res.status(404).type('txt').send('Not found');
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
|
||||||
exports.send404 = async function (req, res) {
|
exports.send404 = helpers.try(async (req, res) => {
|
||||||
res.status(404);
|
res.status(404);
|
||||||
const path = String(req.path || '');
|
const path = String(req.path || '');
|
||||||
if (res.locals.isAPI) {
|
if (res.locals.isAPI) {
|
||||||
@@ -66,4 +66,4 @@ exports.send404 = async function (req, res) {
|
|||||||
bodyClass: helpers.buildBodyClass(req, res),
|
bodyClass: helpers.buildBodyClass(req, res),
|
||||||
icon: icons[Math.floor(Math.random() * icons.length)],
|
icon: icons[Math.floor(Math.random() * icons.length)],
|
||||||
});
|
});
|
||||||
};
|
});
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const util = require('util');
|
|
||||||
|
|
||||||
const user = require('../user');
|
const user = require('../user');
|
||||||
const plugins = require('../plugins');
|
const plugins = require('../plugins');
|
||||||
const helpers = require('./helpers');
|
const helpers = require('./helpers');
|
||||||
@@ -13,6 +11,15 @@ const controllers = {
|
|||||||
const middleware = module.exports;
|
const middleware = module.exports;
|
||||||
|
|
||||||
middleware.buildHeader = helpers.try(async (req, res, next) => {
|
middleware.buildHeader = helpers.try(async (req, res, next) => {
|
||||||
|
await doBuildHeader(req, res);
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
|
middleware.buildHeaderAsync = async (req, res) => {
|
||||||
|
await doBuildHeader(req, res);
|
||||||
|
};
|
||||||
|
|
||||||
|
async function doBuildHeader(req, res) {
|
||||||
res.locals.renderHeader = true;
|
res.locals.renderHeader = true;
|
||||||
res.locals.isAPI = false;
|
res.locals.isAPI = false;
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
@@ -33,7 +40,4 @@ middleware.buildHeader = helpers.try(async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
res.locals.config = config;
|
res.locals.config = config;
|
||||||
next();
|
}
|
||||||
});
|
|
||||||
|
|
||||||
middleware.buildHeaderAsync = util.promisify(middleware.buildHeader);
|
|
||||||
|
|||||||
Reference in New Issue
Block a user