Skip to content

Commit

Permalink
Redirect before static files
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinKolarik committed Dec 14, 2024
1 parent c9918d8 commit 74295c1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
19 changes: 16 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,11 @@ app.use(render({
assetsVersion,
}, app));

/**
* Redirect old URLs #1.
*/

if (site === 'jsdelivr') {
/**
* Redirect old URLs #1.
*/
app.use(async (ctx, next) => {
if (!ctx.query._escaped_fragment_) {
return next();
Expand All @@ -165,6 +166,18 @@ if (site === 'jsdelivr') {
return ctx.redirect(`/package/${legacyMapping[name].type}/${legacyMapping[name].name}`);
}
});

/**
* Redirect previous Globalping pages.
*/
app.use(async (ctx, next) => {
if (/^\/globalping(?:\/|$)/.test(ctx.path)) {
ctx.status = 301;
return ctx.redirect(`https://globalping.io${ctx.url.replace(/^\/[^/?]+/, '')}`);
}

return next();
});
}

/**
Expand Down
9 changes: 0 additions & 9 deletions src/routes/jsdelivr.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,4 @@ koaElasticUtils.addRoutes(router, [
[ '/open-graph/image/npm/:name', '/open-graph/image/:type(npm)/:scope?/:name' ],
], ogImage);


/**
* Redirect previous Globalping pages.
*/
router.get('/globalping/:path(.*)?', async (ctx) => {
ctx.status = 301;
return ctx.redirect(`https://globalping.io${ctx.url.replace(/^\/[^/?]+/, '')}`);
});

module.exports = router;

0 comments on commit 74295c1

Please sign in to comment.