MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / onRequest

Function onRequest

apps/marketing/src/middleware.ts:17–34  ·  view source on GitHub ↗
(context, next)

Source from the content-addressed store, hash-verified

15const POSTHOG_PROXY_PATH = "/_astro/_ph";
16
17export const onRequest: MiddlewareHandler = async (context, next) => {
18 const { pathname } = new URL(context.request.url);
19 if (pathname !== POSTHOG_PROXY_PATH && !pathname.startsWith(`${POSTHOG_PROXY_PATH}/`)) {
20 return next();
21 }
22
23 const url = new URL(context.request.url);
24 url.hostname = pathname.startsWith(`${POSTHOG_PROXY_PATH}/static/`)
25 ? POSTHOG_ASSETS_HOST
26 : POSTHOG_INGEST_HOST;
27 url.protocol = "https:";
28 url.port = "";
29 url.pathname = pathname.slice(POSTHOG_PROXY_PATH.length) || "/";
30
31 const upstream = new Request(url, context.request);
32 upstream.headers.delete("cookie");
33 return fetch(upstream);
34};

Callers

nothing calls this directly

Calls 3

deleteMethod · 0.65
nextFunction · 0.50
fetchFunction · 0.50

Tested by

no test coverage detected