1<script setup lang="ts">
2// SSR reads the worker environment through nitro's cloudflare_module runtime
3// contract: `event.context.cloudflare.env`. `useState` serializes the
4// server-read value into the payload so the client render matches.
5const config = useRuntimeConfig();
6const secret = useState("fixture-secret", () => {
7 if (import.meta.server) {
8 const event = useRequestEvent();
9 const env = event?.context.cloudflare?.env as
10 | Record<string, unknown>
11 | undefined;
12 return typeof env?.FIXTURE_SECRET === "string"
13 ? env.FIXTURE_SECRET
14 : "missing";
15 }
16 return "missing";
17});
18</script>
19
20<template>
21 <main>
22 <h1 data-testid="page-marker">NUXT_FIXTURE</h1>
23 <p data-testid="config-marker">{{ config.public.fixtureMarker }}</p>
24 <p data-testid="env-secret">secret:{{ secret }}</p>
25 </main>
26</template>