History

Drop astro:middleware dependency in marketing types

CI runs typecheck on Node 20, but `astro sync` (which generates the virtual `astro:middleware` module's types into .astro/types.d.ts) requires Node 22+. Use the public MiddlewareHandler type from `astro` instead and add a small env.d.ts that references astro/client so `import.meta.env` is typed without needing astro sync.

Rhys Sullivan committed 6 months ago

Commit f00160d1 parent 5bd6f903 files · +12 −5Browse files

Unified · Split

3 files
  1. apps/marketing/package.json +2 −2
  2. apps/marketing/src/env.d.ts +7 −0
  3. apps/marketing/src/middleware.ts +3 −3
apps/marketing/package.json+2−2
@@ -10,8 +10,8 @@ · 9 unmodified lines
1010 "preview": "astro preview",
1111 "deploy": "astro build && npx wrangler deploy --config dist/server/wrangler.json",
1212 "astro": "astro",
13− "typecheck": "astro sync && tsgo --noEmit",
14− "typecheck:slow": "astro sync && tsc --noEmit"
13+ "typecheck": "tsgo --noEmit",
14+ "typecheck:slow": "tsc --noEmit"
1515 },
1616 "dependencies": {
1717 "@astrojs/cloudflare": "^13.0.0",
apps/marketing/src/env.d.ts+7−0
@@ -0,0 +1,7 @@
1+/// <reference types="astro/client" />
2+
3+interface ImportMetaEnv {
4+ readonly PUBLIC_POSTHOG_KEY?: string;
5+ readonly PUBLIC_POSTHOG_HOST?: string;
6+ readonly PUBLIC_ANALYTICS_PATH?: string;
7+}
apps/marketing/src/middleware.ts+3−3
@@ -1,4 +1,4 @@
1−import { defineMiddleware } from "astro:middleware";
1+import type { MiddlewareHandler } from "astro";
22
33 // PostHog reverse proxy — the browser SDK targets a build-randomized
44 // first-party path and we forward to PostHog's ingest + asset hosts. Keeps
@@ -12,7 +12,7 @@ const POSTHOG_PROXY_PATH = `/api/${(import.meta.env.PUBLIC_ANALYTICS_PATH ?? "a" · 7 unmodified lines
1212 "",
1313 )}`;
1414
15−export const onRequest = defineMiddleware(async (context, next) => {
15+export const onRequest: MiddlewareHandler = async (context, next) => {
1616 const { pathname } = new URL(context.request.url);
1717 if (pathname !== POSTHOG_PROXY_PATH && !pathname.startsWith(`${POSTHOG_PROXY_PATH}/`)) {
1818 return next();
@@ -29,4 +29,4 @@ export const onRequest = defineMiddleware(async (context, next) => { · 10 unmodified lines
2929 const upstream = new Request(url, context.request);
3030 upstream.headers.delete("cookie");
3131 return fetch(upstream);
32−});
32+};