NeonN
Neon2y ago
4 replies
rubber-blue

How to use Neon WSProxy with Prisma and Vercel Edge Functions.

I'm currently having trouble Neon's WS Proxy (Here) with Prisma, especially how I should fill out the variables and what URIs I should put in.

My .env currently:
DATABASE_URL="postgresql://coolperson:<private>@example.com:1234/postgres"


My db.ts:
import { PrismaClient } from '@prisma/client';
import { neonConfig, Pool } from '@neondatabase/serverless';
import { PrismaNeon } from '@prisma/adapter-neon';

// Copied from https://github.com/prisma/prisma/issues/21310#issuecomment-2023676550
if (global.WebSocket === undefined) {
  const ws = require('ws')
  neonConfig.webSocketConstructor = ws
}

let databaseUrl = process.env.DATABASE_URL;

if (databaseUrl.includes('localhost')) {
  neonConfig.wsProxy = () => `wsproxy.example.com:3456/v1`
  neonConfig.useSecureWebSocket = false
  neonConfig.pipelineConnect = false
}

const pool = new Pool({ connectionString: databaseUrl })
const adapter = new PrismaNeon(pool)
const prisma = new PrismaClient({
  adapter,
  datasources: {
    db: { url: 'wsproxy.example.com:3456' },
  },
})

export default prisma;


There are errors but the errors just come from how the libraries cannot connect to the database.
Was this page helpful?