julianpoy/RecipeSage-selfhost

Postgres host not read from env var

Closed this issue · 2 comments

Hi, It seems that the environment variable given to the recipesage api container POSTGRES_HOST=recipesage-postgres is not taken into account at some point by the api. I can create users but not recipes. I was not able to find a hard coded value of the postgres host in the source code.

EDIT: so far this error only happens for "My recipes" at /#/list/main and "People" at /#/people
Here is the error:

Can't reach database server at `postgres`:`5432`

Please make sure your database server is running at `postgres`:`5432`.
    at An.handleRequestError (/app/node_modules/@prisma/client/runtime/library.js:174:7205)
    ... 8 lines matching cause stack trace ...
    at async /app/node_modules/@trpc/server/dist/adapters/express.js:20:9 {
  code: 'INTERNAL_SERVER_ERROR',
  name: 'TRPCError',
  [cause]: PrismaClientInitializationError:
  Invalid `prisma.session.findFirst()` invocation in
  /app/packages/trpc/src/context.ts:13:38

    10 const token = req.headers.authorization.split(" ")[1];
    11 if (!token) return null;
    12
  → 13 const session = prisma.session.findFirst(
  Can't reach database server at `postgres`:`5432`

  Please make sure your database server is running at `postgres`:`5432`.
      at An.handleRequestError (/app/node_modules/@prisma/client/runtime/library.js:174:7205)
      at An.handleAndLogRequestError (/app/node_modules/@prisma/client/runtime/library.js:174:6358)
      at /app/node_modules/@prisma/client/runtime/library.js:177:2908
      at async /app/node_modules/@prisma/client/runtime/library.js:177:3123
      at async t._executeRequest (/app/node_modules/@prisma/client/runtime/library.js:177:10621)
      at async Object.createContext (/app/packages/trpc/src/context.ts:24:19)
      at async Object.createContext (/app/node_modules/@trpc/server/dist/nodeHTTPRequestHandler-071d36b5.js:14:20)
      at async Object.resolveHTTPResponse (/app/node_modules/@trpc/server/dist/resolveHTTPResponse-1f03fdfd.js:161:15)
      at async /app/node_modules/@trpc/server/dist/nodeHTTPRequestHandler-071d36b5.js:69:9
      at async /app/node_modules/@trpc/server/dist/adapters/express.js:20:9 {
    clientVersion: '4.15.0',
    errorCode: undefined
  }
} Error:
Invalid `prisma.session.findFirst()` invocation in
/app/packages/trpc/src/context.ts:13:38

That makes sense since the new ORM I'm switching to uses the DATABASE_URL env var rather than the POSTGRES_HOST env var. Can you try updating the DATABASE_URL env var host as well and let me know if you still encounter the issue?

Perfect! I am unfamiliar with PostgreSQL connection strings so I didn't know I had to change the host there too. Changing to DATABASE_URL=postgresql://recipesage_selfhost:recipesage_selfhost@recipesage-postgres:5432/recipesage_selfhost fixed it for me.