// Public-site proxy (Next.js 16 rename of "middleware"). Implementation // moved to `@ampless/runtime` (L1 extraction); this file wires the // project's `cms.config` + AppSync endpoint into the factory and // re-exports the default matcher. The runtime export name is still // `createAmplessMiddleware` for API stability; only the user-side // file convention (proxy.ts + `export const proxy`) follows Next 16's // rename. // // See `@ampless/runtime/middleware` for behaviour details: AppSync // flag fetch + Lambda-memory LRU + `/raw/` rewrite for no_layout // HTML, `/static/(/)` rewrite for static bundles, plus // per-post Cache-Control. import cmsConfig from './cms.config' import outputs from './amplify_outputs.json' import { createAmplessMiddleware } from '@ampless/runtime/middleware' // `amplify_outputs.json` is generated by `npx ampx sandbox` / // `npx ampx pipeline-deploy` — the public API key has a 365-day TTL // and is rotated monthly by the api-key-renewer Lambda. See // RUNBOOK.md §"API key rotation". export const proxy = createAmplessMiddleware({ cmsConfig, appsyncUrl: outputs.data.url, // The public API key is always present in production deploys (the // backend declares `apiKeyAuthorizationMode`). The non-null assertion // is honest about the assumption; `ampx sandbox` will surface a clear // error long before middleware ever runs if it ever isn't. apiKey: outputs.data.api_key!, }) // Next.js 16's Turbopack requires `config` to be a statically // analysable object literal — referencing an imported variable // (e.g. `defaultMatcherConfig` from @ampless/runtime/middleware) // causes a build error: // "Next.js can't recognize the exported `config` field in route. // It needs to be a static object." // // So we inline the matcher here. If you change it, keep it in sync // with `defaultMatcherConfig` documented in @ampless/runtime/middleware. // The matcher excludes admin / api / login / static assets / // amplify_outputs.json so the public-site proxy doesn't rewrite // legitimate non-blog routes. export const config = { matcher: [ '/((?!admin|api|login|_next/static|_next/image|favicon\\.ico|amplify_outputs\\.json).*)', ], }