Préfixer les variables StoryBlok avec PUBLIC_ pour les exposer dans import.meta.env
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.
This commit is contained in:
parent
b1d66a9be8
commit
c231016016
4 changed files with 10 additions and 10 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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` |
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue