Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generating static output gives localhost adress #388

Open
patandrick opened this issue Jan 24, 2024 · 0 comments
Open

Generating static output gives localhost adress #388

patandrick opened this issue Jan 24, 2024 · 0 comments

Comments

@patandrick
Copy link

patandrick commented Jan 24, 2024

Hello dear devs!

I found a confusing behaviour of the strapi nuxt module.

I'v got this in my nuxt.config.ts :

...
  runtimeConfig: {
    strapi: {
      url: 'http://localhost:1337',
      prefix: '/api',
      version: 'v4'
    },
    public: {
      strapi: {
        url: 'https://api.domain.de'
      }
    }
  },
...

When I did:

npm run generate

> generate
> nuxt generate

Nuxt 3.8.1 with Nitro 2.7.2                                                                                                          10:29:42 AM
ℹ Strapi Admin URL: https://api.domain.de/admin                                                                          10:29:42 AM
ℹ Building client...                                                                                                                10:29:43 AM
ℹ vite v4.5.0 building for production...

the generated URL for strapi media was http://localhost:1337
but the generated static client does not have access to localhost obviously

I found that in useStrapiMedia.ts there is this line

const config = process.server ? useRuntimeConfig() : useRuntimeConfig().public

I already changed the line to always use the public strapi config and it worked.
Would it be possible to get the public URL for media in the generate task even if process.server returns true?
Otherwise I must open the /api endpoint of strapi and close it afterwards everytime I generate the static client with the prerendered content.

Maybe one way to solve this could be to loop trough process.argv and lookup for 'generate' parameter.
Another way may be to add extra configuration in runtime config and implement a mechanism that checks the parameter, e.g. "generated: true"

Any other suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant