Strapi 4.0 desployed admin keep call to http://localhost:1337/admin/project-type

I deployed it to EC2 instance. But when I try to get in /admin, it calls the API http://localhost:1337/admin/project-type and stuck at loading screen.

Does anyone know why?

I had this too … config is baked in at build time, re-run build with the production config you want

I believe this can be fixed by setting the url property in the config/server.js file.

1 Like

In the /config/server.js file you might have

host: env(‘HOST’, ‘0.0.0.0’),

Replace with the IP of the server and don’t forget to stop and restart npm run develop.

Building your admin UI with development configuration ...
Admin UI built successfully
[2022-02-02 09:18:58.614] debug: ⛔️ Server wasn't able to start properly.
[2022-02-02 09:18:58.616] error: Middleware "strapi::session": App keys are required. Please set app.keys in config/server.js (ex: keys: ['myKeyA', 'myKeyB'])
Error: Middleware "strapi::session": App keys are required. Please set app.keys in config/server.js (ex: keys: ['myKeyA', 'myKeyB'])
    at instantiateMiddleware (/home/tarkhil/my-project/node_modules/@strapi/strapi/lib/services/server/middleware.js:12:11)
    at resolveMiddlewares (/home/tarkhil/my-project/node_modules/@strapi/strapi/lib/services/server/middleware.js:56:18)
    at registerApplicationMiddlewares (/home/tarkhil/my-project/node_modules/@strapi/strapi/lib/services/server/register-middlewares.js:66:29)
    at async Object.initMiddlewares (/home/tarkhil/my-project/node_modules/@strapi/strapi/lib/services/server/index.js:99:7)
    at async Strapi.bootstrap (/home/tarkhil/my-project/node_modules/@strapi/strapi/lib/Strapi.js:396:5)
    at async Strapi.load (/home/tarkhil/my-project/node_modules/@strapi/strapi/lib/Strapi.js:408:5)
    at async Strapi.start (/home/tarkhil/my-project/node_modules/@strapi/strapi/lib/Strapi.js:161:9)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Related Github issue: https://github.com/strapi/strapi/issues/12418

As has been stated above, you need to re-build after deployment

Hi

That issue was locked just now as it’s not considered a bug, but it is a design problem.

@DMehaffy It’s counter intuitive to have an environment variable only valid in build-time but not in run-time. What is more important, having configuration hard-coded instead of using actual environment variables goes against best practices. Take as an example the 12factor application:

Store config in the environment

An app’s config is everything that is likely to vary between deploys (staging, production, developer environments, etc). This includes:

  • Resource handles to the database, Memcached, and other backing services
  • Credentials to external services such as Amazon S3 or Twitter
  • Per-deploy values such as the canonical hostname for the deploy

https://12factor.net/config

As mentioned in some comments, building the application in a Continues Integration system and deploying the code to different environments will not work with Strapi, as it’s hard-coding the url value from config/server.js; even if it is being set to read the value from environment, as it is shows in the server documentation example. So this breaks the III of the 12factors application, which is a bad practice.

The result is that you end up with different code bases for each and all environments, which leads to many different sort of problems, such as it hinders debugging, or simply testing different configurations based on environment variables, or changing the domain name.

It would be very nice to have Strapi follow this practice and read such values from environment on run-time.

Thanks

1 Like

Nothing works, as long as I’m using strapi, “Warning:
An error occurred while requesting the API” is always with me, whether I run 「npm run build」 or not

HI i am facing the same issue. I have replaced the URL. Can someone tell me how i can run deply and run in production?


> headlesscms@0.1.0 develop
> strapi develop

(node:31340) Warning: [deprecated] In future versions, Strapi will stop reading directly from the environment variable API_TOKEN_SALT. Please set apiToken.salt in config/admin.js instead.
For security reasons, keep storing the secret in an environment variable and use env() to read it in config/admin.js (ex: `apiToken: { salt: env('API_TOKEN_SALT') }`). See https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/configurations/optional/environment.html#configuration-using-environment-variables.
(Use `node --trace-warnings ...` to show where the warning was created)
[2023-04-05 12:23:47.429] error: getaddrinfo ENOTFOUND http://ec2-3-8-78-44.eu-west.compute.amazonaws.com
Error: getaddrinfo ENOTFOUND http://ec2-3-8-78-44.eu-west.compute.amazonaws.com
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26)

How are you guys dealing with this? We need to deploy to a bunch of different domains. Is the official solution really to make a separate build for each with just this one enviroment variable changed?

Facing the same issue. Its Years now this issue got documented first. Strapi didn’t make it work until yet ? Really this is too bad.

Dear Strapi Team. It’s a really bad design decision to put such important config in build time. What about keeping things 12 Factor -.-

Did anyone solved this ? I’m sitting here for days now.

This looks like a regression in v4.12.4. We are seeing our existing deployments with this strange behaviour. Any word on this from the Strapi team?

re: Can't load admin panel in 4.12.4 on the public internet · Issue #17634 · strapi/strapi · GitHub

1 Like

For me: run yarn build and yarn develop again

The solution for was downgrade the strapi version, I change "@strapi/strapi": "4.12.4", to "@strapi/strapi": "4.12.1",.
You can check this theard: Can't load admin panel in 4.12.4 on the public internet · Issue #17634 · strapi/strapi · GitHub