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

Function onRequest

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

Source from the content-addressed store, hash-verified

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

Callers 1

stubFetchFunction · 0.85

Calls 3

deleteMethod · 0.65
nextFunction · 0.50
fetchFunction · 0.50

Tested by 1

stubFetchFunction · 0.68