Comments (8)
@awacode21 I don't know if this can be useful, but I kind of solved it in another way, using a plain fetch.
It does not really "feel" like the proper way (I would prefer to use the Storyblok API even here, but this is probably a little developer OCD coming in), but since I only need a single static value to be updated, it does the job.
(I'm using Nuxt in static site generator mode, so I used a server
plugin as I don't need this value to change later)
// /plugins/seo-site-config.server.js
export default defineNuxtPlugin({
name: 'nuxt-seo:dynamic-site-config',
enforce: 'pre',
async setup() {
const response = await fetch(`https://api.storyblok.com/v2/cdn/stories/path/to/my/story?version=draft&token=${process.env.SB_API_TOKEN}`)
const siteSettings = await response.json()
updateSiteConfig({
name: siteSettings.story.content.site_title,
})
},
})
Feel free to adapt it to your use case.
(I'm leaving this open as this is a workaround and not a solution to the original question)
from storyblok-nuxt.
Hi @stefanobartoletti, just wondering if the enforce
option has something to do with it 🤔 because to load/initialize our SDK, we use this plugin: https://github.com/storyblok/storyblok-nuxt/blob/main/src/runtime/plugin.ts, so I guess your plugin doesn't have the context yet, so it wasn't initialized yet when you tried to call useStoryblokApi()
composable.
Any chance you can set up a simple Stackblitz using that specific plugin so I can try to help you with the solution?
In the meantime, you can try enableSudoMode
to true
and define your plugin for initializing the SDK: Define your own plugin, and enforcing it before the one you are running there.
from storyblok-nuxt.
Thank you for your reply, I will check to see what happens when fiddling with enforce
, and see to setup a stackblitz for you ASAP
from storyblok-nuxt.
@Dawntraoz this is a minimal stackblitz, I'm getting some different errors than my local config, but it is still not working, so maybe it can be useful too
https://stackblitz.com/edit/nuxt-starter-zmsdjr?file=plugins%2Fseo-site-config.server.js
Please let me know if you need something else
from storyblok-nuxt.
I'm trying to diagnose this further, I also tried to explicitly importing useStoryblokApi
, like this
import { useStoryblokApi } from '#imports';
export default defineNuxtPlugin({
name: 'nuxt-site-config:overrides',
enforce: 'pre', // makes sure it's ran before nuxt-seo plugin
setup() {
let siteConfig = {};
const storyblokApi = useStoryblokApi();
const { data } = storyblokApi.get('cdn/stories/config/site-config', {
version: 'draft',
});
siteConfig = data.story;
updateSiteConfig({
name: siteConfig.content.site_title,
});
},
});
But it is not working, I get this error, maybe it can help:
[nuxt] [request error] [unhandled] [500] storyblokApi is null
You can't use useStoryblokApi if you're not loading apiPlugin. Please provide it on StoryblokVue initialization.
from storyblok-nuxt.
Sorry to bump this up, is there any news about this?
I can provide more info and context if needed :)
from storyblok-nuxt.
i am dealing with the same question. Any new insights?
from storyblok-nuxt.
@stefanobartoletti thanks for your answer. I did the same this morning.. going with a simple fetch. It solved my problem. But i agree i would prefer to use storyblok api
from storyblok-nuxt.
Related Issues (20)
- Consider giving the option to use `~/components/storyblok` for Storyblok Components HOT 5
- Component could not be found for blok HOT 8
- `renderRichText()` not working HOT 2
- Does preventClicks in Storyblok bridge actually work? HOT 2
- Nuxt 3.4.0 - 3.8.2 + nitro 2.8.0 bug | [ERROR] No matching export in "node_modules/.pnpm/[email protected]/node_modules/unicorn-magic/default.js" for import "toPath" HOT 8
- Cannot read properties of null (reading 'parentNode') and Cannot read properties of null (reading 'subTree')
- cache not working anymore since v6.0.0 HOT 5
- Module breaks types for auto imported components HOT 16
- Enabling the @storyblok/nuxt module causes components to lose typings. HOT 7
- Internal link from rich text editor rendering wrong URL HOT 2
- Use nuxt preview composable to make sure that fetching is done properly
- Storyblok making requests clientside on full static site. HOT 16
- Cache version `cv=undefined` causes redirect HOT 1
- Add the option to set default API version (`draft` or `published`) from Nuxt Config and using an ENV variable HOT 4
- Add routes to " Hit rate limit..." messages. HOT 2
- ERROR Component could not be found for blok "ComponentName"! Is it defined in main.ts as "app.component("ComponentName", ComponentName); HOT 7
- Missing type for componetsDir HOT 2
- useAsyncStoryblok returns undefined when story is not found HOT 1
- Streamlining useAsyncStoryblok to nuxt's useAsyncData HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from storyblok-nuxt.