Not records found in production after deploy

Feature(s) impacted

All views in production are not working.

Observed behavior

I check on REST routes and they for all calls a NOT FOUND error. But database is filled with data and my application is working.

Expected behavior

Display data as it working on development env.

Failure Logs

  • 2023-03-08T13:58:34+01:00 warning: [404] GET /_prisma_migrations/count - 1ms
  • 2023-03-08T13:58:34+01:00 warning: [404] GET /_prisma_migrations - 4ms

Replay HAR : Wormhole - Simple, private file sharing

Context

  • Project name: Flexper Carrefour

  • Team name: Carrefour energie

  • Environment name: Remote DEV

  • Agent (forest package) name & version:
    NPM “@forestadmin/agent”: “^1.8.3”,

  • Database type: Postgres with PRISMA

  • Recent changes made on your end if any:

    “metadata”: {
    “liana”: “forest-nodejs-agent”,
    “liana_version”: “1.8.3”,
    “stack”: {“engine”: “nodejs”, “engine_version”: “18.14.0”}
    }

Hey @qlaffont, and welcome to our community :wave:

So, all the calls to your agent are sending back 404?

Could you confirm the last 4 digits of the FOREST_ENV_SECRET value of the environment that is not working?

Finally, do you use any specific config (Reverse proxy, etc) in front of your agent that can lead to this kind of issue?

Thanks in advance :pray:

So, all the calls to your agent are sending back 404?
Not all just when data are fetched.

Could you confirm the last 4 digits of the FOREST_ENV_SECRET value of the environment that is not working?
Last 4 digit : c394

Finally, do you use any specific config (Reverse proxy, etc) in front of your agent that can lead to this kind of issue?
No. And I’m just using the last fastify and fastify plugin with some configurations.

if (process.env.FOREST_AUTH_SECRET && process.env.FOREST_ENV_SECRET) {
    // TO FIX ISSUE WITH FOREST WHO USE `use` OLD SYNTAX
    await fastify.register(require('@fastify/middie'));

    await createAgent({
      authSecret: process.env.FOREST_AUTH_SECRET!,
      envSecret: process.env.FOREST_ENV_SECRET!,
      isProduction: process.env.NODE_ENV === 'production',
      typingsPath: './typings.ts',
      typingsMaxDepth: 5,
      prefix: 'forestadmin',
    })
      .addDataSource(createSqlDataSource(process.env.DATABASE_URL!))
      .mountOnFastify(fastify)
      .start();
  }

You are using prefix for a specific reason?

According to our documentation, which can be the issue depending on your architecture (And what you filled in the API Endpoint when you created the environment).

Do you have any server startup logs failing on your production environment ?

EDIT: Just checked, and it seems both your environments have the prefix, so doesn’t seems related if it works in development.

yes to isolate forestadmin route. But it’s working on dev.

No I don’t have any error in log for prod :

     2023-03-08T14:20:23+01:00 > node ./dist/src/index.js
    2023-03-08T14:20:29+01:00 info: Successfully mounted on Fastify
    2023-03-08T14:20:29+01:00 warning: Skipping column socket_io_attachments.payload (Unsupported type: BYTEA)
    2023-03-08T14:20:29+01:00 warning: Skipping table "socket_io_attachments" because of error: A column called 'id' was added to the attributes of 'socket_io_attachments' but not marked with 'primaryKey: true'
    2023-03-08T14:20:29+01:00 info: Schema was updated, sending new version
    2023-03-08T14:20:36+01:00 No build cache archive was created. Not uploading anything.
    2023-03-08T14:35:31+01:00 info: [200] POST /authentication - 2ms
    2023-03-08T14:35:32+01:00 info: [200] GET /authentication/callback - 263ms
    2023-03-08T14:35:40+01:00 warning: [404] GET /_prisma_migrations - 4ms
    2023-03-08T14:35:40+01:00 warning: [404] GET /_prisma_migrations/count - 2ms

A few others questions while I’m trying to reproduce this issue on my end:

  • Do you eventually have any models that returns something, or does it happen on every one of them?
  • Are you using v4 of fastify?

It could be worth double checking that your table names matches between your development and production environment. You could easily do so by setting NODE_ENV to dev on your remote environment (just as a quick test, to check if that’s related to your issue), and check that the generated .forestadmin-schema.json is exactly the same.

Do you eventually have any models that returns something, or does it happen on every one of them?

No it return the same thing for every models. Maybe It’s due because we use in databaseurl the option schema ?

Are you using v4 of fastify?

Yes

No it return the same thing for every models. Maybe It’s due because we use in databaseurl the option schema ?

If you suspect the issue to be related to this, the SQL Datasource also support logging to a database using a configuration object (SQL (without ORM) - Node.js Developer Guide).

I remember we had issue in the past when specifying the PostgreSQL Schema in the connection string directly, as the node-pg driver is not crystal clear on them supporting schema.

If this is your issue, setting your NODE_ENV=dev on a remote environment should generate an empty .forestadmin-schema.json

I’m hijacking this thread because we have a pending ticket on the datasource-sql documentation

You can use the following syntax, which is not in the doc (should be an easier change than needing to break your connection string down to pieces)

createSqlDataSource({ uri: 'postgres://....', schema: 'mySchema' })

Finally I fixed the issue by writing a converter from database uri to connection object :slight_smile:

if (process.env.FOREST_AUTH_SECRET && process.env.FOREST_ENV_SECRET) {
    // TO FIX ISSUE WITH FOREST WHO USE `use` old syntax
    await fastify.register(require('@fastify/middie'));

    const url = new URL(process.env.DATABASE_URL!);
    const connectionObject = {
      dialect: url.protocol.split(':')[0],
      database: url.pathname.split('/')[1],
      username: url.username,
      password: url.password,
      host: url.hostname,
      port: url.port ? parseInt(url.port, 10) : undefined,
      schema: url.searchParams.get('schema') || undefined,
    };

    await createAgent({
      authSecret: process.env.FOREST_AUTH_SECRET!,
      envSecret: process.env.FOREST_ENV_SECRET!,
      isProduction: process.env.NODE_ENV === 'production',
      typingsPath: './typings.ts',
      typingsMaxDepth: 5,
      prefix: 'forestadmin',
    })
      //@ts-ignore
      .addDataSource(createSqlDataSource(connectionObject))
      .mountOnFastify(fastify)
      .start();
  }```
2 Likes