From 51a9b2bfa589269932627dab13a5806f49fbeeb2 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Mon, 22 Jul 2019 00:10:27 +0300 Subject: [PATCH] ormconfig: load api or bot .env, whichever exists --- ormconfig.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/ormconfig.js b/ormconfig.js index 9b7d0b1d..ed43e333 100644 --- a/ormconfig.js +++ b/ormconfig.js @@ -1,7 +1,18 @@ -require('dotenv').config(); - +const fs = require('fs'); const path = require('path'); +try { + fs.accessSync(path.resolve(__dirname, 'bot.env')); + require('dotenv').config({ path: path.resolve(__dirname, 'bot.env') }); +} catch (e) { + try { + fs.accessSync(path.resolve(__dirname, 'api.env')); + require('dotenv').config({ path: path.resolve(__dirname, 'api.env') }); + } catch (e) { + throw new Error("bot.env or api.env required"); + } +} + const moment = require('moment-timezone'); moment.tz.setDefault('UTC');