@@ -3,47 +3,10 @@ import { PrismaPg } from '@prisma/adapter-pg';
33
44const globalForPrisma = global as unknown as { prisma : PrismaClient } ;
55
6- /**
7- * Derive pg SSL config from the DATABASE_URL.
8- *
9- * pg@8+ defaults rejectUnauthorized to true, which rejects AWS RDS Proxy's
10- * certificate (signed by internal AWS CA, not in Node.js root CA store).
11- *
12- * Per PostgreSQL sslmode spec:
13- * - disable: no SSL
14- * - require: encrypt, skip certificate verification
15- * - verify-ca: encrypt + verify CA
16- * - verify-full: encrypt + verify CA + hostname
17- *
18- * When no sslmode is set, we default to SSL with rejectUnauthorized: false
19- * for non-localhost connections (matches Prisma v6 behavior where the Rust
20- * engine silently accepted all certificates).
21- */
22- function getSslConfig ( url : string ) : boolean | { rejectUnauthorized : boolean } | undefined {
23- const sslmodeMatch = url . match ( / s s l m o d e = ( \w [ \w - ] * ) / ) ;
24-
25- if ( sslmodeMatch ) {
26- switch ( sslmodeMatch [ 1 ] ) {
27- case 'disable' :
28- return undefined ;
29- case 'require' :
30- case 'no-verify' :
31- return { rejectUnauthorized : false } ;
32- case 'verify-ca' :
33- case 'verify-full' :
34- return { rejectUnauthorized : true } ;
35- }
36- }
37-
38- // No sslmode specified — enable SSL for non-localhost (production default)
39- const isLocalhost = / l o c a l h o s t | 1 2 7 \. 0 \. 0 \. 1 | : : 1 / . test ( url ) ;
40- return isLocalhost ? undefined : { rejectUnauthorized : false } ;
41- }
42-
436function createPrismaClient ( ) : PrismaClient {
447 const url = process . env . DATABASE_URL ! ;
45- const ssl = getSslConfig ( url ) ;
46- const adapter = new PrismaPg ( { connectionString : url , ssl } ) ;
8+ const isLocalhost = / l o c a l h o s t | 1 2 7 \. 0 \. 0 \. 1 | : : 1 / . test ( url ) ;
9+ const adapter = new PrismaPg ( { connectionString : url , ssl : isLocalhost ? undefined : true } ) ;
4710 return new PrismaClient ( { adapter } ) ;
4811}
4912
0 commit comments