Skip to content

Commit 97ea93e

Browse files
fix: add CF function for edge level deprecation (#641)
* chore: add function for deprecation * fix: adddd await before calling next
1 parent 5f0fd49 commit 97ea93e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

functions/_middleware.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export async function onRequest(context) {
2+
const { env, next } = context;
3+
4+
const IS_DEPRECATED = env.DEPRECATED !== 'false';
5+
6+
if (IS_DEPRECATED) {
7+
return new Response(
8+
'This site has been deprecated. Please use main-site.',
9+
{
10+
status: 410,
11+
headers: {
12+
'Content-Type': 'text/plain; charset=utf-8',
13+
'Cache-Control': 'no-store',
14+
},
15+
}
16+
);
17+
}
18+
19+
return await next();
20+
}

0 commit comments

Comments
 (0)