nuxt-modules / nuxt-modules/strapi

Generating static output gives localhost adress

Open
#388 0 comments 0 reactions 0 assignees View on GitHub

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

https://github.com/nuxt-modules/strapi/blob/5d3994d4a6754ce0c7350513d9cc6b8bf541dbbb/src/runtime/composables/useStrapiMedia.ts#L5

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.