Setup with Express/Sequelize stuck on "Waiting for your backend to run"

Update 2 hours later: Same project I go to from the Projects list page I get a popup that says " Unable to authenticate you" with further text below in orange: “Please verify that your admin backend is correctly configured and running, and that you have access to the internet.”

In the console it originally had two issues:

  1. The URL “https://app.forestadmin.com” was blocked by cors, but I managed to fix that with the following:
app.use(
  cors({
    origin: "https://app.forestadmin.com",
    credentials: true,
  })
);
  1. But the second persists: “POST http://localhost:8000/forest/authentication 404 (Not Found)”. I don’t know what to do about this one because I do have the following code:
forest
  .init({
    envSecret:
      "e763ee2f4eee49902e3f27afb66b489018c4548820c8fa80dd27db2824de1984",
    authSecret: "0789b20f46bd6729af437ea94e430a11dad57829c8fc624a",
    objectMapping: Sequelize,
    connections: { default: db.sequelize },
  })
  .then((FAMiddleware) => {
    app.use(FAMiddleware);
  });

Expected behavior

It should automatically detect that I ran the server.

Update: It should authenticate me when I have the project running and I open the Project page to view the admin panel.

Actual behavior

It gets stuck on “Waiting for your backend to run” with the green dot blinking.

Update: I get a popup that says " Unable to authenticate you" with further text below in orange: “Please verify that your admin backend is correctly configured and running, and that you have access to the internet.”

Failure Logs

In the console I get: “POST http://localhost:8000/forest/authentication 404 (Not Found)”

Context

Please provide any relevant information about your setup.

  • Package Version: 8.2.2
  • Express Version: 4.17.1
  • Sequelize Version: 6.6.5
  • Database Dialect: PostgreSQL
  • Database Version: 8.7.1 (version of “pg” from package.json)
  • Project Name: Holy War Clone

Hi @Mshary_AlSharekh,

Did you try to access http://localhost:8000 in your browser ? Does it display something ?

localhost:8000 is running my express server, it shows me the following:

{"message":"Path not found."}

I can use the rest of the server just fine. Using Postman I can login and get a token, the rest of my routes work as expected.

Hi @Mshary_AlSharekh !
Can you check on your browser logs if any other request is failing ?
There should be two call to /forest/authentication, one of them should be an OPTION call, does it fail too ?

Yes, I’m seeing two. The first is the preflight which gets status 204, the second is the fetch which gets status 404.

I did all this using the datasource type “Express / Sequelize”. This is because it’s best and most ideal and convenient for me to have it as part of my existing express project.

I just tried creating a new project using the datasource type “PostgreSQL”, and followed the instructions. It worked without a hitch. So I may end up going that route, but I still would like it if the setup with my existing project would work, it would simplify my workflow.

I don’t know how relevant this is to this discussion, but I thought I should share it.

You mean that you tried to integrate Forest inside your own app ?

Did you follow all the instructions of the installation process ? It might be a problem with your CORS config still, did you exclude all the /forest route from your app cors config ?

I did follow them. When I did I ended up with two issues:

  1. The CORS issue where the domain app.forestadmin.com was not allowed through
  2. The second error in the console right below it is the same one I mentioned above on /forest/authentication

I made adjustments to the code that resolved the CORS issue. I’ll show you everything…

Here’s the code I have from the instructions:

// Forest Admin
const forest = require("forest-express-sequelize");
const Sequelize = require("sequelize");

app.use(
  "^(?!forest/?$).*",
  cors({
    origin: ["https://app.forestadmin.com", "http://localhost:8000"],
    credentials: true,
  })
);

forest
  .init({
    envSecret: process.env.FOREST_ENV_SECRET,
    authSecret: process.env.FOREST_AUTH_SECRET,
    objectMapping: Sequelize,
    connections: { default: db.sequelize },
  })
  .then((FAMiddleware) => {
    app.use(FAMiddleware);
  });

Here’s the errors I’m getting using this code:

Access to fetch at 'http://localhost:8000/forest/authentication' from origin 'https://app.forestadmin.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

POST http://localhost:8000/forest/authentication net::ERR_FAILED

I made adjustments to the code to this:

app.use(
  cors({
    origin: ["https://app.forestadmin.com", "http://localhost:8000"],
    credentials: true,
  })
);

With this, the error is this:

POST http://localhost:8000/forest/authentication 404 (Not Found)

There’s a lot I feel I don’t understand about CORS, so I’m kinda walking blind here.

1 Like

It looks like you don’t have the specific cors exeption that needs to be implemented for the /forest/authentication route, see this code:

let allowedOrigins = [/\.forestadmin\.com$/, /localhost:\d{4}$/];

if (process.env.CORS_ORIGINS) {
  allowedOrigins = allowedOrigins.concat(process.env.CORS_ORIGINS.split(','));
}

const corsConfig = {
  origin: allowedOrigins,
  maxAge: 86400, // NOTICE: 1 day
  credentials: true,
};

app.use('/forest/authentication', cors({
  ...corsConfig,
  // The null origin is sent by browsers for redirected AJAX calls
  // we need to support this in authentication routes because OIDC
  // redirects to the callback route
  origin: corsConfig.origin.concat('null')
}));
app.use(cors(corsConfig));

Can you try it ?

Yeap I tried same as. But ı found solution. I need to change my error handler on express, I am making a video for explanation.
But thanks your help

1 Like

I think many of these problems may be explained by changes to Chrome (if you’re using it). Chrome now requires a specific header in the OPTIONS response to show that requests to localhost should be allowed, as shown in this comment: [Question / Feature Request] CORS-RFC1918 Support · Issue #236 · expressjs/cors · GitHub

@anon94532230 I created a basic repo to replicate the issue. I am also not able to configure forest-express-sequelize for my local environment.