Branchwell

Jobley / website / functions / _middleware.js

1import { appSiteAssociation, setupLinkPage } from '../src/passkeys.js';
2
3// Protect retired website routes without touching R2 artifacts.
4export function isRetiredNativeRoute(pathname) {
5 let path = pathname;
6 try { path = decodeURIComponent(pathname); } catch {}
7 return /^\/(?:downloads\/.+|appcast[^/]*\.xml\/?)(?:$)/i.test(path);
8}
9
10export async function onRequest(context) {
11 const { request, next } = context;
12 const url = new URL(request.url);
13 const path = url.pathname;
14
15 // Passkeys: Apple's app-site association (webcredentials) and where a setup link lands in a browser.
16 if (path === '/.well-known/apple-app-site-association') return appSiteAssociation();
17 if (path === '/passkey' || path === '/passkey/') return setupLinkPage();
18
19 if (path === '/analytics-consent.gif') {
20 return new Response(null, { status: 410, headers: { 'Cache-Control': 'no-store' } });
21 }
22
23 if (isRetiredNativeRoute(path)) {
24 return new Response(request.method === 'HEAD' ? null : 'Jobley is now website-only. Find volunteer work at https://jobley.ai/volunteer/.', {
25 status: 410,
26 headers: {
27 'Cache-Control': 'no-store',
28 'Content-Type': 'text/plain; charset=utf-8',
29 'X-Content-Type-Options': 'nosniff',
30 'X-Robots-Tag': 'noindex',
31 },
32 });
33 }
34
35 return next();
36}