Skip to content

Commit 04fcbee

Browse files
committed
feat(redirects): add middleware for site migration
Implements redirect logic in Oak middleware to forward migrated pages to esolia.co.jp/en while keeping non-migrated content serving from esolia.com. Allows incremental migration without breaking existing URLs.
1 parent 9e19d7f commit 04fcbee

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

static/index.en.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,42 @@ app.use(async (ctx, next) => {
2424
ctx.response.headers.set("Permissions-Policy", "accelerometer=(), ambient-light-sensor=*, autoplay=(self), battery=(self), camera=(), cross-origin-isolated=*, fullscreen=*, geolocation=(self), gyroscope=(), magnetometer=(), microphone=(), midi=(), payment=(), picture-in-picture=(), usb=()");
2525
});
2626

27+
// Redirect middleware
28+
app.use(async (ctx, next) => {
29+
const path = ctx.request.url.pathname;
30+
31+
// Specific page redirects
32+
const redirects: Record<string, string> = {
33+
"/privacy": "https://esolia.co.jp/en/privacy",
34+
"/esolia-code-of-conduct": "https://esolia.co.jp/en/coc",
35+
};
36+
37+
if (redirects[path]) {
38+
ctx.response.redirect(redirects[path]);
39+
ctx.response.status = 301;
40+
return; // Stop processing, don't call next()
41+
}
42+
43+
// Homepage redirect
44+
if (path === "/") {
45+
ctx.response.redirect("https://esolia.co.jp/en/");
46+
ctx.response.status = 301;
47+
return;
48+
}
49+
50+
// Pages to serve as-is (optional - just document them)
51+
// If a file exists, it will be served by the static handler below
52+
// Examples: /terms.html, /privacy.html, /legacy-docs/guide.html
53+
54+
// For catch-all redirect of everything else, uncomment these lines:
55+
// ctx.response.redirect(`https://esolia.co.jp/en${path}`);
56+
// ctx.response.status = 301;
57+
// return;
58+
59+
// Otherwise, continue to static file handler
60+
await next();
61+
});
62+
2763
app.use(async (ctx) => {
2864
try {
2965
await ctx.send({

0 commit comments

Comments
 (0)