mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
🐛 Fixed throwing errors during link redirects
no issue Errors weren't correctly passed on to Express in the middleware.
This commit is contained in:
parent
f7aefa2feb
commit
b7be02f057
1 changed files with 25 additions and 21 deletions
|
@ -85,6 +85,7 @@ class LinkRedirectsService {
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
async handleRequest(req, res, next) {
|
async handleRequest(req, res, next) {
|
||||||
|
try {
|
||||||
// skip handling if original url doesn't match the prefix
|
// skip handling if original url doesn't match the prefix
|
||||||
const fullURLWithRedirectPrefix = `${this.#baseURL.pathname}${this.#redirectURLPrefix}`;
|
const fullURLWithRedirectPrefix = `${this.#baseURL.pathname}${this.#redirectURLPrefix}`;
|
||||||
if (!req.originalUrl.startsWith(fullURLWithRedirectPrefix)) {
|
if (!req.originalUrl.startsWith(fullURLWithRedirectPrefix)) {
|
||||||
|
@ -107,6 +108,9 @@ class LinkRedirectsService {
|
||||||
|
|
||||||
res.setHeader('X-Robots-Tag', 'noindex, nofollow');
|
res.setHeader('X-Robots-Tag', 'noindex, nofollow');
|
||||||
return res.redirect(link.to.href);
|
return res.redirect(link.to.href);
|
||||||
|
} catch (e) {
|
||||||
|
return next(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue