chore(DO): trying loading cert form file
authorxangelo <me@xangelo.ca>
Wed, 4 Dec 2024 20:27:42 +0000 (15:27 -0500)
committerxangelo <me@xangelo.ca>
Wed, 4 Dec 2024 20:31:07 +0000 (15:31 -0500)
knexfile.ts
src/server/lib/db.ts

index ea4b0b7ce4049c8370f5a44c45947baccf7ad2c8..751c83bc67c32e36275d1cb19861099389001df8 100644 (file)
@@ -1,9 +1,12 @@
 import { config as dotenv } from 'dotenv';
 import type { Knex } from "knex";
+import { readFileSync, writeFileSync } from 'fs';
+import path from 'path';
 
 dotenv();
 
 const connectionUrl = process.env.DATABASE_URL;
+writeFileSync(path.join(__dirname, 'ca.cert'), process.env.CA_CERT as string);
 
 const config: { [key: string]: Knex.Config } = {
   development: {
@@ -11,8 +14,7 @@ const config: { [key: string]: Knex.Config } = {
     connection: {
       connectionString: connectionUrl,
       ssl: {
-        rejectUnauthorized: false,
-        ca: process.env.CA_CERT
+        ca: readFileSync(path.join(__dirname, 'ca.crt'))
       }
     },
     pool: {
@@ -29,8 +31,7 @@ const config: { [key: string]: Knex.Config } = {
     connection: {
       connectionString: connectionUrl,
       ssl: {
-        rejectUnauthorized: false,
-        ca: process.env.CA_CERT
+        ca: readFileSync(path.join(__dirname, 'ca.crt'))
       }
     },
     pool: {
index 6a19281d3941cda3010d3bb96495400b766ff15f..7a0b7dcc328afbd68620bf8c6f21a198421e09f1 100644 (file)
@@ -1,17 +1,20 @@
 import knex from "knex";
 import { config as dotenv } from 'dotenv';
+import { readFileSync, writeFileSync } from 'fs';
+import path from 'path';
 
 dotenv();
 
 const connectionUrl = process.env.DATABASE_URL;
 
+writeFileSync(path.join(__dirname, 'ca.crt'), process.env.CA_CERT as string);
+
 export const db = knex({
   client: 'pg',
   connection: {
     connectionString: connectionUrl,
     ssl: {
-      rejectUnauthorized: false,
-      ca: process.env.CA_CERT
+      ca: readFileSync(path.join(__dirname, 'ca.crt'))
     }
   }
 });