1import { cloudflare } from "@octanejs/adapter-cloudflare";
2import { defineConfig, RenderRoute, ServerRoute } from "@octanejs/vite-plugin";
3
4/**
5 * The Cloudflare request context the adapter forwards as `context.platform`
6 * in production. In dev, Octane's Vite middleware supplies no platform
7 * (upstream limitation), so handlers must tolerate `undefined`.
8 */
9interface Platform {
10 readonly env?: Record<string, unknown>;
11 readonly ctx?: { readonly waitUntil?: unknown };
12}
13
14export default defineConfig({
15 adapter: cloudflare(),
16 router: {
17 routes: [
18 new ServerRoute({
19 path: "/api/hello",
20 methods: ["GET"],
21 handler: (context) => {
22 const platform = context.platform as Platform | undefined;
23 return Response.json({
24 marker: "api-route-ok",
25 secret:
26 (platform?.env?.FIXTURE_SECRET as string | undefined) ?? null,
27 hasWaitUntil: typeof platform?.ctx?.waitUntil === "function",
28 });
29 },
30 }),
31 new RenderRoute({ path: "/", entry: ["App", "/src/App.tsx"] }),
32 ],
33 },
34});