Deployed strapi admin panel trying to hit localhost:1337

After editing my server.js file to add a public URL:

module.exports = ({ env }) => ({
  host: env('HOST', '0.0.0.0'),
  url: env("PUBLIC_URL", "http://localhost:1337"),
  port: env.int('PORT', 1337),
  app: {
    keys: env.array('APP_KEYS'),
  },
  webhooks: {
    populateRelations: env.bool('WEBHOOKS_POPULATE_RELATIONS', false),
  },
});

I started getting the issue reported above on my deployed instance, the PUBLIC_URL would always default. It turns out this is compiled into admin build-time so if you have it setup like this, you will need to supply the PUBLIC_URL as a build-time argument to your docker file:

Docker

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

Build:

docker build --build-arg="NODE_ENV=production" --build-arg="PUBLIC_URL=${{ env.PUBLIC_URL }}"
1 Like