From 2023d366036cc7b3a3249008d662559a6c0190ba Mon Sep 17 00:00:00 2001 From: wiz Date: Mon, 14 Mar 2022 13:11:04 +0000 Subject: [PATCH] Cleanup MySQL unix socket code and add to sample config --- backend/mempool-config.sample.json | 1 + backend/src/config.ts | 4 ++-- backend/src/database.ts | 9 +++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/backend/mempool-config.sample.json b/backend/mempool-config.sample.json index 5c45838ee..b5c4b8d53 100644 --- a/backend/mempool-config.sample.json +++ b/backend/mempool-config.sample.json @@ -44,6 +44,7 @@ "ENABLED": true, "HOST": "127.0.0.1", "PORT": 3306, + "SOCKET": "/var/run/mysql/mysql.sock", "DATABASE": "mempool", "USERNAME": "mempool", "PASSWORD": "mempool" diff --git a/backend/src/config.ts b/backend/src/config.ts index 7bb99b429..9ceb66e59 100644 --- a/backend/src/config.ts +++ b/backend/src/config.ts @@ -43,7 +43,7 @@ interface IConfig { DATABASE: { ENABLED: boolean; HOST: string, - SOCKET: string | undefined, + SOCKET: string, PORT: number; DATABASE: string; USERNAME: string; @@ -122,7 +122,7 @@ const defaults: IConfig = { 'DATABASE': { 'ENABLED': true, 'HOST': '127.0.0.1', - 'SOCKET': undefined, + 'SOCKET': '', 'PORT': 3306, 'DATABASE': 'mempool', 'USERNAME': 'mempool', diff --git a/backend/src/database.ts b/backend/src/database.ts index b106c6ec9..55be0ffc3 100644 --- a/backend/src/database.ts +++ b/backend/src/database.ts @@ -15,10 +15,11 @@ export class DB { timezone: '+00:00', } - if (config.DATABASE.SOCKET && config.DATABASE.SOCKET != "") - poolConfig.socketPath = config.DATABASE.SOCKET - else - poolConfig.host = config.DATABASE.HOST + if (config.DATABASE.SOCKET !== "") { + poolConfig.socketPath = config.DATABASE.SOCKET; + } else { + poolConfig.host = config.DATABASE.HOST; + } return poolConfig; }