From c231016016474ece4a9157c8e1f934cd1e8ddd29 Mon Sep 17 00:00:00 2001 From: Jalil Arfaoui Date: Sat, 7 Mar 2026 01:27:43 +0100 Subject: [PATCH] =?UTF-8?q?Pr=C3=A9fixer=20les=20variables=20StoryBlok=20a?= =?UTF-8?q?vec=20PUBLIC=5F=20pour=20les=20exposer=20dans=20import.meta.env?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Les variables système (Clever Cloud) n'étaient pas disponibles via import.meta.env car Vite ne les inclut que pour les variables préfixées PUBLIC_. Sans ce préfixe, getVersion() était compilé à "published" même sur l'instance preview, empêchant le live preview du visual editor StoryBlok. --- .env.example | 4 ++-- README.md | 8 ++++---- astro.config.mjs | 6 +++--- src/lib/storyblok.ts | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.env.example b/.env.example index e1b914c..17ffaf4 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,6 @@ # Token StoryBlok — Preview token en dev/preview, Public token en production -STORYBLOK_TOKEN= +PUBLIC_STORYBLOK_TOKEN= # Mettre à true sur l'instance preview (SSR + visual editor StoryBlok) # Ne pas définir ou mettre à false en production (SSG) -# STORYBLOK_IS_PREVIEW=true +# PUBLIC_STORYBLOK_IS_PREVIEW=true diff --git a/README.md b/README.md index 0761b9b..b3dbd49 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Le serveur démarre sur `http://localhost:3030`. ## Builds -Le projet supporte deux modes de build via la variable `STORYBLOK_IS_PREVIEW` : +Le projet supporte deux modes de build via la variable `PUBLIC_STORYBLOK_IS_PREVIEW` : ### Production (SSG) @@ -37,7 +37,7 @@ Génère des fichiers HTML statiques dans `dist/`. Le rebuild doit être déclen Serveur Node.js avec le **visual editor StoryBlok** (bridge + live preview). Utilise le **Preview Access Token** et récupère le contenu en **draft**. ```bash -STORYBLOK_IS_PREVIEW=true npm run build +PUBLIC_STORYBLOK_IS_PREVIEW=true npm run build HOST=0.0.0.0 node dist/server/entry.mjs ``` @@ -47,8 +47,8 @@ Le serveur démarre sur le port `8080` par défaut (configurable via `PORT`). | Variable | Production | Preview | |---|---|---| -| `STORYBLOK_TOKEN` | Public Access Token | Preview Access Token | -| `STORYBLOK_IS_PREVIEW` | *(non défini)* | `true` | +| `PUBLIC_STORYBLOK_TOKEN` | Public Access Token | Preview Access Token | +| `PUBLIC_STORYBLOK_IS_PREVIEW` | *(non défini)* | `true` | | `CC_POST_BUILD_HOOK` | `npm run build` | `npm run build` | | `HOST` | - | `0.0.0.0` | diff --git a/astro.config.mjs b/astro.config.mjs index 6fa28de..f55fba1 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -6,8 +6,8 @@ import icon from 'astro-icon'; import node from '@astrojs/node'; import { storyblok } from '@storyblok/astro'; -const env = loadEnv('', process.cwd(), 'STORYBLOK'); -const isPreview = env.STORYBLOK_IS_PREVIEW === 'true'; +const env = loadEnv('', process.cwd(), 'PUBLIC_STORYBLOK'); +const isPreview = env.PUBLIC_STORYBLOK_IS_PREVIEW === 'true'; export default defineConfig({ output: isPreview ? 'server' : 'static', @@ -15,7 +15,7 @@ export default defineConfig({ integrations: [ icon(), storyblok({ - accessToken: env.STORYBLOK_TOKEN, + accessToken: env.PUBLIC_STORYBLOK_TOKEN, bridge: isPreview, livePreview: isPreview, }), diff --git a/src/lib/storyblok.ts b/src/lib/storyblok.ts index e0cb65e..6b89027 100644 --- a/src/lib/storyblok.ts +++ b/src/lib/storyblok.ts @@ -2,7 +2,7 @@ import { useStoryblokApi } from '@storyblok/astro'; import type { SbBlokData } from '@storyblok/astro'; function getVersion(): 'draft' | 'published' { - return import.meta.env.STORYBLOK_IS_PREVIEW === 'true' ? 'draft' : 'published'; + return import.meta.env.PUBLIC_STORYBLOK_IS_PREVIEW === 'true' ? 'draft' : 'published'; } export interface Spectacle {