remix-run / blues-stack

The Remix Stack for deploying to Fly with PostgreSQL, authentication, testing, linting, formatting, etc.
https://remix.run/stacks
MIT License
944 stars 232 forks source link

Error connect database #88

Closed zevsdflkjiuxcvb closed 4 months ago

zevsdflkjiuxcvb commented 2 years ago

Have you experienced this bug with the latest version of the template?

yes

Steps to Reproduce

Run npx create-remix --template remix-run/blues-stack in console then npm run dev, I get this error Here is my db URL in .env file: DATABASE_URL="postgresql://postgres:norqgrhigqygxsywkasp@db.norqgrhigqygxsywkasp.supabase.co:5432/postgres"

app ready: http://localhost:3000
(node:9388) UnhandledPromiseRejectionWarning: Error: Can't reach database server at `undefined.db.norqgrhigqygxsywkasp.supabase.co`:`5432`

Please make sure your database server is running at `undefined.db.norqgrhigqygxsywkasp.supabase.co`:`5432`.
    at D:\job\test\remix-blue\node_modules\@prisma\client\runtime\index.js:44801:20
(Use `node --trace-warnings ...` to show where the warning was created)
(node:9388) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:9388) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Expected Behavior

Just hope plug and run :(

Actual Behavior

image

mcansh commented 2 years ago

did you opt out of installing dependencies during "create-remix"? if not, a .env file should have been generated for you during "remix init" with the contents of .env.example https://github.com/remix-run/blues-stack/blob/main/remix.init/index.js#L63

if you do opt out, you should be seeing the following which prompts you to install your dependencies and run "npx remix init"

mcansh commented 2 years ago

ah actually, re-read your issue, looks like the DB url the app has isn't correct (see undefined)

zevsdflkjiuxcvb commented 2 years ago

undefined

Yeah I know, but why? I should be ran, right ?

mcansh commented 2 years ago

what's weird is there is no subdomain before .db.nor... so im not sure where the undefined is even coming from

juanmcampos commented 2 years ago

It seems to come from db.server.ts file there is a conditional if (!isLocalHost) { } which sets the databaseurl for FLY_REGION which if you are not using and you are not localhost then it breaks.

juanmcampos commented 2 years ago

I made a PR with a quick fix :P maybe not the best solution but hope it helps https://github.com/remix-run/blues-stack/pull/101

phifa commented 1 year ago

I just ran into the same issue. It's not fixed, is it?

machour commented 1 year ago

@phifa if the issue is still open then most likely not. Check the pull request #101 and if it works for you, then comment there to validate it and get this fixed 👍

tylerdukedev commented 1 year ago

UPDATE:

~~Anyone find a solution for this? I'm running in to the same issue. I've altered my db.server file to something more generic:

import { PrismaClient } from "@prisma/client";

let db: PrismaClient;

declare global {
  var db: PrismaClient | undefined;
}

// PrismaClient is attached to the `global` object in development to prevent
// exhausting your database connection limit.
if (process.env.NODE_ENV === "production") {
  db = new PrismaClient();
  db.$connect();
} else {
  if (!global.db) {
    global.db = new PrismaClient();
    global.db.$connect();
  }

  db = global.db;
}

export default db;

Still doesn't work.~~

machour commented 4 months ago

Fixed by #187