Skip to content

Commit 326f383

Browse files
committed
chore(db): ssl mode fix
1 parent 93a0acd commit 326f383

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

drizzle.config.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import 'dotenv/config';
22
import type { Config } from 'drizzle-kit';
3+
4+
const isRunningLocally = () =>
5+
process.env.NUXT_DB_HOST?.includes('localhost') || process.env.NUXT_DB_HOST?.includes('127.0.0.1');
6+
37
export default {
48
schema: './server/db/schema.ts',
59
out: './server/db/migrations',
@@ -10,6 +14,6 @@ export default {
1014
user: process.env.NUXT_DB_USER!,
1115
password: process.env.NUXT_DB_PASSWORD!,
1216
database: process.env.NUXT_DB_DATABASE!,
13-
ssl: false,
17+
ssl: !isRunningLocally(),
1418
},
1519
} satisfies Config;

server/utils/db.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import pg from 'pg';
55
let client: pg.Client | null;
66
let drizzleInstance: NodePgDatabase;
77

8+
const isRunningLocally = () =>
9+
process.env.NUXT_DB_HOST?.includes('localhost') || process.env.NUXT_DB_HOST?.includes('127.0.0.1');
10+
811
export async function useDatabase() {
912
try {
1013
const config = useRuntimeConfig();
@@ -14,10 +17,10 @@ export async function useDatabase() {
1417

1518
client = new pg.Client({
1619
...config.db,
17-
ssl: IS_DEV
20+
ssl: isRunningLocally()
1821
? false
1922
: {
20-
rejectUnauthorized: false, // TODO: fix this.
23+
rejectUnauthorized: false,
2124
},
2225
});
2326

0 commit comments

Comments
 (0)