First time linking vercel to railway
madster456
HOBBYOP

a year ago

I am so beyond confused right now.

I have a railway database, and a vercel project.

The vercel project is set to connect to DATABASE_URL, but i'm getting this error:

The provided database string is invalid. Error parsing connection string: empty host in database URL. Please refer to the documentation in https://www.prisma.io/docs/reference/database-reference/connection-urls for constructing a correct connection string. In some cases, certain characters must be escaped. Please check the string for any illegal characters.
Health check failed: PrismaClientInitializationError: 
Invalid `prisma.$queryRaw()` invocation:
The provided database string is invalid. Error parsing connection string: empty host in database URL. Please refer to the documentation in https://www.prisma.io/docs/reference/database-reference/connection-urls for constructing a correct connection string. In some cases, certain characters must be escaped. Please check the string for any illegal characters.
    at _n.handleRequestError (/vercel/path0/node_modules/@prisma/client/runtime/library.js:123:7154)
    ...... {
  clientVersion: '5.10.2',
  errorCode: undefined

Well, that doesn't make sense.

0 Replies

madster456
HOBBYOP

a year ago

So i created a health check endpoint, see whats going on:

{
  "status": "unhealthy",
  "error": "\nInvalid `prisma.$queryRaw()` invocation:\n\n\nThe provided database string is invalid. Error parsing connection string: empty host in database URL. Please refer to the documentation in https://www.prisma.io/docs/reference/database-reference/connection-urls for constructing a correct connection string. In some cases, certain characters must be escaped. Please check the string for any illegal characters.",
  "environment": {
    "DATABASE_URL": true
  }
}

Okay….

I look at the built DATABASE_URL from railway after linking, its missing the host in the constructed URL?


madster456
HOBBYOP

a year ago

0f00bfc3-da53-48f5-8c1a-963b0ac9f76e


brody
EMPLOYEE

a year ago

can you show me what you mean please?


madster456
HOBBYOP

a year ago

Imported vars directly after linking vercel and railway.

1323560810458648600


madster456
HOBBYOP

a year ago

import { PrismaClient } from '@prisma/client'

const prismaClientSingleton = () => {
  if (!process.env.DATABASE_URL) {
    throw new Error('DATABASE_URL environment variable is not set');
  }

  return new PrismaClient({
    datasources: {
      db: {
        url: process.env.DATABASE_URL
      }
    },
    log: ['error', 'warn']
  });
}

declare global {
  var prisma: undefined | ReturnType
}

const prisma = globalThis.prisma ?? prismaClientSingleton()

if (process.env.NODE_ENV !== 'production') globalThis.prisma = prisma

export { prisma }

brody
EMPLOYEE

a year ago

can you show me the missing host? of course hiding the password portion


madster456
HOBBYOP

a year ago

I unlinked them, and relinked. Host is there now, but its @postgres.railway.interal, is that correct for the vercel app? I would think that internal wouldn't work with vercel, no?

Either way, after unlinking and relinking the host is there, but cleared cache on vercel, redeploy, and still getting the same error on build.


brody
EMPLOYEE

a year ago

you would indeed need to use the public url


madster456
HOBBYOP

a year ago

"For example, if you have a Railway project with the Postgres plugin, the DATABASE_URL variable will be available to your Vercel deployments."

From vercel's site


madster456
HOBBYOP

a year ago

Just heads up. Switched to DATABASE_PUBLIC_URL for connection, trying redeploy now.


brody
EMPLOYEE

a year ago

looks like their docs are outdated by quite a while


madster456
HOBBYOP

a year ago

Can't reach database server at `postgres.railway.internal`:`5432`
Please make sure your database server is running at `postgres.railway.internal`:`5432`.
    at _n.handleRequestError (/vercel/path0/node_modules/@prisma/client/runtime/library.js:123:7154)
    at _n.handleAndLogRequestError (/vercel/path0/node_modules/@prisma/client/runtime/library.js:123:6188)
    at _n.request (/vercel/path0/node_modules/@prisma/client/runtime/library.js:123:5896)
    at async l (/vercel/path0/node_modules/@prisma/client/runtime/library.js:128:10871)
    at async c (/vercel/path0/.next/server/app/api/health/route.js:1:807)
    at async /vercel/path0/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:37010
    at async eC.execute (/vercel/path0/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:27552)
    at async eC.handle (/vercel/path0/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:38344)
    at async exportAppRoute (/vercel/path0/node_modules/next/dist/export/routes/app-route.js:77:26)
    at async exportPageImpl (/vercel/path0/node_modules/next/dist/export/worker.js:175:20) {
  clientVersion: '5.10.2',
  errorCode: undefined

I don't get it.

This is with using DATABASE_PUBLIC_URL.


madster456
HOBBYOP

a year ago

I have not touched the vars in vercel env, only let railway import them.


brody
EMPLOYEE

a year ago

postgres.railway.internal would be from the private url


brody
EMPLOYEE

a year ago

or from PGHOST


maddsua
HOBBY

a year ago

Well it still looks like a private network url, domains that end with .railway.internal cannot be used outside of railway projects (think of it as service names in a docker compose created network)


maddsua
HOBBY

a year ago

You need to give vercel a url with a domain that looks like "…something.proxy.rlwy.net"


maddsua
HOBBY

a year ago

Also a really simple way to check if a domain is publicly accessible is to just ping it with a standard ping command


maddsua
HOBBY

a year ago

If you can access it from your machine, so can vercel


Loading...