storyblok-nuxt
storyblok-nuxt copied to clipboard
Support runtimeConfig
Right now the accessToken
is compiled into the plugin. Would be great if storyblok would support nuxt runtimeConfig.
Example how @nuxtjs/axios implemented it: https://github.com/nuxt-community/axios-module/commit/351ea5ee459eea53b9124de75ebfa7674d7ccd40
I have added the support in my pr :)
Where is this feature? We've come to realize that we cannot use Storyblok with our Nuxt site unless it supports runtimeConfig, or another method of utilizing a preview key in our non production environments, and a public key on our production environment without recompiling the source.
I have added the support in my pr :)
Hi! Can you please explain/show how? :(
There is a workaround.
I'm using preview token for all envs, and just keep version draft/published in publicRuntimeConfig
Per docs:
To make the API as explorable as possible, accounts have draft versions and published version of API tokens. To access the draft version of your content you can use the preview token, and for receiving published content you can use the public token. The preview token is able to also load the published content. To switch between those versions you can append the query parameter
version=draft/published
and using the appropriate token to perform a draft or published version call.
Setup Example:
// .env.development
STORYBLOK_API_KEY = some_preview_token
STORYBLOK_VERSION = draft
// .env.production
STORYBLOK_API_KEY = some_preview_token
STORYBLOK_VERSION = published
// nuxt.config.js
publicRuntimeConfig: {
...
storyblokVersion: process.env.STORYBLOK_VERSION,
...
}
// vue file
const response = await this.$storyapi.get(path, {
"version": this.$config.storyblokVersion,
});
@coremyslo Perfect workaround, thanks a lot! Still requires to add version manually on every request.. but that's the best we have now!
As this issue was created when this module was used for Nuxt 2, we will focus on the support on the new issue -> https://github.com/storyblok/storyblok-nuxt/issues/217 and close this one.
For the same issue in the Nuxt 2 module, go to -> https://github.com/storyblok/storyblok-nuxt-2/issues