diff --git a/functions/_middleware.js b/functions/_middleware.js new file mode 100644 index 00000000..e5a2d4a9 --- /dev/null +++ b/functions/_middleware.js @@ -0,0 +1,20 @@ +export async function onRequest(context) { + const { env, next } = context; + + const IS_DEPRECATED = env.DEPRECATED !== 'false'; + + if (IS_DEPRECATED) { + return new Response( + 'This site has been deprecated. Please use main-site.', + { + status: 410, + headers: { + 'Content-Type': 'text/plain; charset=utf-8', + 'Cache-Control': 'no-store', + }, + } + ); + } + + return await next(); +}