From aaeaac02851cb93f9900e8b102e851d400ef3f90 Mon Sep 17 00:00:00 2001 From: Bruno Bernardino Date: Thu, 26 Dec 2024 11:46:45 +0000 Subject: [PATCH] Update Deno, update Render deploy file Fixes #33 Fixes #30 (hopefully, can't replicate) --- .dvmrc | 2 +- Dockerfile | 2 +- lib/interfaces/database.ts | 39 ++++++++++++++++++++++++++++---------- render.yaml | 2 +- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/.dvmrc b/.dvmrc index eca07e4..7d2ed7c 100644 --- a/.dvmrc +++ b/.dvmrc @@ -1 +1 @@ -2.1.2 +2.1.4 diff --git a/Dockerfile b/Dockerfile index 584be99..8be0484 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM denoland/deno:ubuntu-2.1.2 +FROM denoland/deno:ubuntu-2.1.4 EXPOSE 8000 diff --git a/lib/interfaces/database.ts b/lib/interfaces/database.ts index 6eccd8e..1ffea29 100644 --- a/lib/interfaces/database.ts +++ b/lib/interfaces/database.ts @@ -33,18 +33,37 @@ export default class Database { return this.db; } - const postgresClient = new Client({ - user: POSTGRESQL_USER, - password: POSTGRESQL_PASSWORD, - database: POSTGRESQL_DBNAME, - hostname: POSTGRESQL_HOST, - port: POSTGRESQL_PORT, - tls, - }); + try { + const postgresClient = new Client({ + user: POSTGRESQL_USER, + password: POSTGRESQL_PASSWORD, + database: POSTGRESQL_DBNAME, + hostname: POSTGRESQL_HOST, + port: POSTGRESQL_PORT, + tls, + }); - await postgresClient.connect(); + await postgresClient.connect(); - this.db = postgresClient; + this.db = postgresClient; + } catch (error) { + // Try to connect without TLS, if the connection type is socket + if ((error as Error).toString().includes('No TLS options are allowed when host type is set to "socket"')) { + const postgresClient = new Client({ + user: POSTGRESQL_USER, + password: POSTGRESQL_PASSWORD, + database: POSTGRESQL_DBNAME, + hostname: POSTGRESQL_HOST, + port: POSTGRESQL_PORT, + }); + + await postgresClient.connect(); + + this.db = postgresClient; + } else { + throw error; + } + } } protected async disconnectFromPostgres() { diff --git a/render.yaml b/render.yaml index 9a04424..a065ee9 100644 --- a/render.yaml +++ b/render.yaml @@ -33,4 +33,4 @@ services: databases: - name: bewcloud - plan: starter + plan: basic-256mb