Skip to content

Commit

Permalink
fix: fix pg ssl error
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanvanherwijnen committed Aug 28, 2024
1 parent 302abfc commit 1fc74fc
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions packages/api/src/kysely/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand All @@ -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
})
})

Expand Down

0 comments on commit 1fc74fc

Please sign in to comment.