-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.js
More file actions
41 lines (34 loc) · 1.04 KB
/
middleware.js
File metadata and controls
41 lines (34 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
export const config = {
matcher: ['/:path*'],
};
const REDIRECTS = {
'nic.mc.ecustcic.com': 'nic.ecustcic.com',
};
export function middleware(context) {
const url = new URL(context.request.url);
const target = REDIRECTS[url.hostname];
if (target) {
const dest = `${url.protocol}//${target}${url.pathname}${url.search}`;
return Response.redirect(dest, 301);
}
if (url.pathname === '/favicon.ico') {
return Response.redirect(`${url.origin}/ecustcic.png`, 301);
}
if (context.request.method === 'OPTIONS') {
return new Response(null, {
status: 204,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type',
'Access-Control-Max-Age': '86400',
},
});
}
if (url.pathname === '/api/health') {
return new Response(JSON.stringify({ status: 'ok', timestamp: Date.now() }), {
headers: { 'Content-Type': 'application/json' },
});
}
return context.next();
}