Skip to content

Commit

Permalink
fix: fix postgres ssl
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanvanherwijnen committed Aug 28, 2024
1 parent 1fc74fc commit 2f15da4
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions packages/api/src/kysely/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,32 @@ 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
// https://www.digitalocean.com/community/questions/cannot-connect-with-dev-database-due-to-ssl-issue
const ssl =
env.read('POSTGRES_SSL') || env.read('VITE_POSTGRES_SSL')
? {
rejectUnauthorized: false,
ca: process.env.CACERT
}
: false

export const postgresConnectionString = `postgress://${user}:${password}@${host}:${port}/${database}?sslmode=${ssl ? (ssl.rejectUnauthorized ? 'prefer' : 'no-verify') : ''}&sslrootcert=${ssl ? (ssl.ca ? ssl.ca : '') : ''}`

const dialect = new PostgresDialect({
pool: new Pool({
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
host,
user,
password,
database,
port,
ssl
})
})

Expand Down

0 comments on commit 2f15da4

Please sign in to comment.