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

Custom url not set during build time breaks admin routing #124

Open
ErgEnn opened this issue Aug 25, 2024 · 1 comment
Open

Custom url not set during build time breaks admin routing #124

ErgEnn opened this issue Aug 25, 2024 · 1 comment
Assignees

Comments

@ErgEnn
Copy link

ErgEnn commented Aug 25, 2024

πŸ› Bug Report

πŸ€·β€β™€οΈ What did you do

When updating the server.js to include url: env('PUBLIC_URL', 'http://localhost:1337') the admin interface routes don't get set correctly since the env var is not included in docker build container.

E.g.

server.js
url: env('PUBLIC_URL', 'http://localhost:1337')

set environment variable:
PUBLIC_URL=http://localhost:1337/cms

run:
docker build -t strapi .
docker run strapi

Strapi says that admin url is http://localhost:1337/cms/admin

Navigating to http://localhost:1337/cms/admin loads the html, but the JS paths are <script src='/admin/main.....' />, not <script src='/cms/admin/main.....' /> (note the missing /cms).

This is due to admin panel being built in React and it needs to know the url during build time to correctly set the paths.

πŸ™‡β€β™€οΈ Expected behavior/code

When environment variable for url is set, the admin dashboard is built using the appropriate url.

πŸ‘©β€πŸ’» Environment

  • πŸ“¦ Node version: 18 / 20
  • πŸ’» OS: Windows

πŸ’‘ Possible Solution

Add following lines to generated Dockerfile:

ARG PUBLIC_URL=http://localhost:1337
ENV PUBLIC_URL=${PUBLIC_URL}

Note: the name PUBLIC_URL needs to be the same as the argument in your url: env('PUBLIC_URL') call in server.js

@ErgEnn
Copy link
Author

ErgEnn commented Aug 27, 2024

Turns out also STRAPI_ADMIN_BACKEND_URL needs to be set during build time since some places us it for url generation
e.g. https://github.com/strapi/strapi/blob/171c6daa568f68cd001f5c65d22fb934cd295edf/packages/core/admin/admin/src/render.ts#L31C47-L31C71

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

3 participants
@Eventyret @ErgEnn and others