nuxt-modules / nuxt-modules/strapi
Generating static output gives localhost adress
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 717
- Forks
- 89
- Avg merge
- 7h 3m
- Merged PRs (30d)
- 6
Description
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
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?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/runtime/composables/useStrapiMedia.ts and the runtimeConfig values shown in the issue. Reproduce the behavior with npm run generate and inspect the generated media URL when process.server is true. Done means generated static output uses the configured public Strapi URL rather than localhost.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nuxtjs, typescript
- Domain
- build-system, frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100