Git Product home page Git Product logo

Comments (4)

Dawntraoz avatar Dawntraoz commented on June 2, 2024 1

Hi @stefanobartoletti 💜

Let's try something! Is it possible that the call is being made in the client side? If that's the case, did you try using the .env variables with this prefix: NUXT_PUBLIC_?

from storyblok-nuxt.

alvarosabu avatar alvarosabu commented on June 2, 2024 1

Hi @stefanobartoletti, what I recommend you do is to add the variables to the runtimeConfig.public on the nuxt.config.ts:

export default defineNuxtConfig({
  runtimeConfig: {
    public: {
      storyblokVersion: process.env.STORYBLOK_VERSION || 'published',
    },
  },
})

And then:

const config = useRuntimeConfig()

const story = await useAsyncStoryblok(
  'blog',
  { version: config.public.storyblokVersion, resolve_relations: 'overview.featured_story' },
  { resolveRelations: 'overview.featured_story' },
)

//or 

const { data: articles } = await storyblokApi.get('cdn/stories', {
  version: config.public.storyblokVersion,
  starts_with: 'blog',
  is_startpage: false,
})

from storyblok-nuxt.

Dawntraoz avatar Dawntraoz commented on June 2, 2024 1

Perfect! As @stefanobartoletti mentioned, it will be nice to add it to the README. Since you already gave an example, can you update the README with the runtimeConfig example @alvarosabu? Thanks in advance. You are the best!

PS: Just to let you know, we had this workaround in the last part of the UT, but for another variable (NODE_ENV) https://www.storyblok.com/tp/create-a-preview-environment-for-your-nuxt-3-website/.

from storyblok-nuxt.

stefanobartoletti avatar stefanobartoletti commented on June 2, 2024

Thanks to both of you for your answers!

I tried both solutions and the one that works best in my implementation is @alvarosabu's.

I think that this is some valuable information that maybe could also be included in the module readme, so even other people could benefit from it (I think it could be a common need to differentiate between environments)

Anyway, thanks for your support 🙏🏻

from storyblok-nuxt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.