Deployed strapi admin panel trying to hit localhost:1337

For me, simply rebuilding the panel BEFORE running yarn dev / yarn start helped.
This helped me:

rm -r .cache build node_modules yarn.lock package-lock.json
yarn
yarn build
yarn dev

From there you can try if it all works and then CTRL+C quit the process and continue with your production build and pm2.

1 Like

Hey, if you run your project in production mode it is working as well? I have the same issue with the problem redirecting the /init to localhost instead to my domain.

Esto me ayudó. Al final hice muchos ajustes.
1-construir e iniciar con (NODE_ENV=production npm run build / NODE_ENV=production npm start)
2-editar el archivo confing/server.js y agregar (url: env(‘PUBLIC_URL’ “HTTP://publicIP”) DEBO INTENTAR CON MI DOMINIO AQUÍ*
3-Agregar la variable STRAPI_ADMIN_BACKEND_URL=sin ningun valor en el .env
4-rm -R yarn.lock, node_modules, package-lock.json
5-y funcionó!!!

Acepto sugerencias y comentarios. :smiley:

*INFO *
NPM 14.21.1 strapi 4.4.6

Hi all. I’m trying to do
1.NODE_ENV=production npm run build
2. NODE_ENV=production npm run start

But there is still a message in the console
http://localhost:1337/admin/project-type

//./config/server.js module.exports = ({ env }) => ({ host: env('HOST', '0.0.0.0'), port: env.int('PORT', 1337), app: { keys: env.array('APP_KEYS'), }, });

=> NOT WORKING
STRAPI_ADMIN_BACKEND_URL=
=> NOT WORKING
Create ./config/env/production/server.js

{
admin : {
url: env(“PUBLIC_URL”)
}
}

PUBLIC_URL=http://XXX.XXX.XX.XXX/admin

=> NOT WORKING TOO
Create ./config/env/production/server.js

{
url: env(“PUBLIC_URL”)
}

PUBLIC_URL=http://XXX.XXX.XX.XXX

Lost 1 day of my life …

1 Like

I have the same problem. I’m building in Azure, but setting NODE_ENV=production. Getting the same error with localhost:1337 url request when accessing the admin area.

I have ‘localhost’ in my configs anywhere I can find…

I think this might be an issue with 4.4.7.

Thank you, Mansoor! The STRAPI_ADMIN_BACKEND_URL= worked for me for version 4.5.1. As the ‘npm run build’ just did not want to fix the problem

We had the same problem with versions 4.5.6 and 4.6.0 on some projects, and we finally realised that it was a problem with imports in our custom plugins. Try to check if you plugins can be built properly.

Changes in imports, e.g:

// before
import { Button } from "@strapi/design-system/Button";

// after
import { Button } from "@strapi/design-system";

How did incorrect plugin imports affect the backendURL?

How did you figure this out?

I’m faced with a similar problem where the admin panel attempts to GET from localhost, despite NODE_ENV and STRAPI_ADMIN_BACKEND_URL being set during build.

rm -r .cache build node_modules yarn.lock package-lock.json
yarn
yarn build
yarn dev

worked for me, too

After finding on internet, I figured out that we need to build out app.

I was abit confused with the NODE_ENV=production, thought it’s for production already, but no, it just builds the app in production mode.

So after you have your project generated with strapi new ... , we need to add our own Dockerfile, I take it from Strapi sample production Dockerfile. Then we build our own image and run it.

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 team @DMehaffy,

Any consideration of this widespread issue? It seems that the topic is not solved, it will soon be 2 years old and seems a very basic functionality we reasonably expect for a CMS. Taking as it is strapi’s sample projects (from npx, foodvisor…) and building with the method described in the doc just doesn’t work. Keeps hitting localhost

Could you please provide a detailed, reproducible way to avoid this error?

We would all be grateful :pray:t2:

strapi is very good but running it only on localhost it’s not that useful :heartbeat:

1 Like

Totally agree, this is a huge pain point which is preventing lots of people and organizations using Strapi as their to-go preferred headless cms.

2 weeks has passed since I started getting this problem and I didn’t found a solution yet. Still trying but if someone could provide a proven and reproducible way to deploy a strapi app in production then yeah, this could be great for all of us struggling with this issue.

:thinking: Total javascript / nodejs noob guy here. :grinning_face_with_smiling_eyes:

I am trying to do this:

process.env.PUBLIC_URL for a plugin, but the PUBLIC_URL says undefined.

This PUBLIC_URL should automatically change depending if it is localhost or on an actual www domain.

The error I am receiving.

The resource from “http://localhost:1337/admin/content-manager/collectionType/api::article.article/undefined/tinymce/tinymce.min.js” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).

From this plugin index.js

...
{process.env.url + '/tinymce/tinymce.min.js'}
...

My current development config/server.js

'use strict';

const cronTasks = require('./src/cron-tasks');

module.exports = ({ env }) => ({
  host: env('HOST', '0.0.0.0'),
  port: env.int('PORT', 1337),
  url: 'http://localhost:1337',
  cron: {
    enabled: true,
    tasks: cronTasks,
  },
  app: {
    keys: env.array('APP_KEYS', ['toBeModified1', 'toBeModified2']),
  },
  webhooks: {
    // TODO: V5, set to false by default
    // Receive populated relations in webhook and db lifecycle payloads
    // This only populates relations in all content-manager endpoints
    populateRelations: env.bool('WEBHOOKS_POPULATE_RELATIONS', true),
  },
});

TinyMCE self-hosted is looking for this file:

tinymceScriptSrc={process.env.PUBLIC_URL + '/tinymce/tinymce.min.js'}

but PUBLIC_URL is undefined. This file is located in the local root tinymce plugin directory via public/tinymce/tinymce.min.js.

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

I looked around and found
Server | Strapi Documentation page.

After I added both

url: env('PUBLIC_URL', 'https://api.example.com'),
proxy: env.bool('IS_PROXIED', true),

My server on Azure web app is working and no longer hit localhost:1337

hoped this helps :slight_smile:

Worked for me !

Hello Sir, I need the same error as you, I am deployed on Ali cloud function, may I ask how to solve this problem without rebuilding, thank you