From 1fc74fc37996c5a2e01810f9b4fd8bb705b1ecb5 Mon Sep 17 00:00:00 2001 From: Stefan van Herwijnen Date: Wed, 28 Aug 2024 11:27:51 +0200 Subject: [PATCH] fix: fix pg ssl error --- packages/api/src/kysely/index.ts | 34 +++++++++++++++----------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/packages/api/src/kysely/index.ts b/packages/api/src/kysely/index.ts index 31ae4ae..48ff2f0 100644 --- a/packages/api/src/kysely/index.ts +++ b/packages/api/src/kysely/index.ts @@ -2,6 +2,7 @@ import pg from 'pg' const { Pool } = pg import { Kysely, PostgresDialect, CamelCasePlugin } from 'kysely' import env from '@vitrify/tools/env' +// import type { Database as OidcDatabase } from '@modular-api/fastify-oidc' import type { DB } from './types.d.ts' export interface Database extends DB {} @@ -19,26 +20,23 @@ types.setTypeParser(1700, function (val) { types.setTypeParser(1114, (str) => str) types.setTypeParser(1082, (str) => str) -const host = env.read('POSTGRES_HOST') || env.read('VITE_POSTGRES_HOST') -const user = - env.read('POSTGRES_USER') || env.read('VITE_POSTGRES_USER') || 'postgres' -const password = - env.read('POSTGRES_PASSWORD') || env.read('VITE_POSTGRES_PASSWORD') -const database = env.read('POSTGRES_DB') || env.read('VITE_POSTGRES_DB') -const port = env.read('POSTGRES_PORT') || env.read('VITE_POSTGRES_PORT') || 5432 -const ssl = - env.read('POSTGRES_SSL') || env.read('VITE_POSTGRES_SSL') ? true : false - -export const postgresConnectionString = `postgress://${user}:${password}@${host}:${port}/${database}` - const dialect = new PostgresDialect({ pool: new Pool({ - host, - user, - password, - database, - port, - ssl + host: env.read('POSTGRES_HOST') || env.read('VITE_POSTGRES_HOST'), + user: + env.read('POSTGRES_USER') || env.read('VITE_POSTGRES_USER') || 'postgres', + password: + env.read('POSTGRES_PASSWORD') || env.read('VITE_POSTGRES_PASSWORD'), + database: env.read('POSTGRES_DB') || env.read('VITE_POSTGRES_DB'), + port: env.read('POSTGRES_PORT') || env.read('VITE_POSTGRES_PORT') || 5432, + // https://www.digitalocean.com/community/questions/cannot-connect-with-dev-database-due-to-ssl-issue + ssl: + env.read('POSTGRES_SSL') || env.read('VITE_POSTGRES_SSL') + ? { + rejectUnauthorized: false, + ca: process.env.CACERT + } + : false }) })