Skip to content

Commit 1d8e02f

Browse files
committed
fix: redirects
1 parent 5a17966 commit 1d8e02f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

server/middleware/canonical-redirects.global.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,29 @@
88
* - /org/* → /@*
99
* - /* → /package/* (Unless it's an existing page)
1010
*/
11+
const pages = [
12+
'/about',
13+
'/compare',
14+
'/org',
15+
'/package',
16+
'/package-code',
17+
'/package-docs',
18+
'/privacy',
19+
'/search',
20+
'/settings',
21+
]
1122
export default defineEventHandler(async event => {
1223
const path = event.path
1324

25+
// username
26+
if (path.startsWith('~')) {
27+
return
28+
}
29+
30+
if (pages.some(page => path === page || path.startsWith(page + '/'))) {
31+
return
32+
}
33+
1434
// /@org/pkg or /pkg → /package/org/pkg or /package/pkg
1535
let pkgMatch = path.match(/^\/(?:(?<org>@[^/]+)\/)?(?<name>[^/@]+)$/)
1636
if (pkgMatch?.groups) {

0 commit comments

Comments
 (0)