Graphley / website / functions / _middleware.js
| 1 | export function onRequest({ request, next }) { |
| 2 | const path = new URL(request.url).pathname; |
| 3 | if (/^\/terms(?:\/index\.html)?\/?$/i.test(path)) { |
| 4 | return new Response(null, { status: 301, headers: { Location: '/privacy/' } }); |
| 5 | } |
| 6 | if (['/analytics-consent.gif', '/assets/analytics.js', '/assets/analytics.css'].includes(path)) { |
| 7 | return new Response(null, { status: 410, headers: { 'Cache-Control': 'no-store' } }); |
| 8 | } |
| 9 | if (/^\/(?:download|downloads)(?:\/|$)|^\/appcast(?:-legacy)?\.xml(?:\/|$)/i.test(path)) { |
| 10 | return new Response(request.method === 'HEAD' ? null : 'Graphley is no longer publicly distributed.\n', { |
| 11 | status: 410, |
| 12 | headers: { 'Content-Type': 'text/plain; charset=utf-8', 'Cache-Control': 'no-store' }, |
| 13 | }); |
| 14 | } |
| 15 | return next(); |
| 16 | } |