refactor: change .env to be dotenv (#1341)

This commit is contained in:
Jef LeCompte
2020-12-11 01:57:49 -05:00
committed by GitHub
parent 0683430768
commit 9b3906ca00
9 changed files with 27 additions and 23 deletions
+10 -6
View File
@@ -1,10 +1,14 @@
import {banner} from './banner';
import {config as config_} from 'dotenv';
import dotenv from 'dotenv';
import path from 'path';
import {readFileSync} from 'fs';
config_({path: path.resolve(__dirname, '../.env')});
if (path.resolve(__dirname, '../dotenv').length > 0) {
dotenv.config({path: path.resolve(__dirname, '../dotenv')});
} else {
dotenv.config({path: path.resolve(__dirname, '../.env')});
}
console.info(
banner.render(
@@ -66,8 +70,8 @@ function envOrNumber(environment: string | undefined, number?: number): number {
/**
* Returns environment variable, given number, or default number,
* while handling .env input errors for a Min/Max pair.
* .env errors handled:
* while handling dotenv input errors for a Min/Max pair.
* dotenv errors handled:
* - Min/Max swapped (Min larger than Max, Max smaller than Min)
* - Min larger than default Max when no Max defined
* - Max smaller than default Min when no Min defined
@@ -106,8 +110,8 @@ function envOrNumberMin(
/**
* Returns environment variable, given number, or default number,
* while handling .env input errors for a Min/Max pair.
* .env errors handled:
* while handling dotenv input errors for a Min/Max pair.
* dotenv errors handled:
* - Min/Max swapped (Min larger than Max, Max smaller than Min)
* - Min larger than default Max when no Max defined
* - Max smaller than default Min when no Min defined
+2 -2
View File
@@ -1,6 +1,6 @@
import {startAPIServer, stopAPIServer} from './web';
import {config} from './config'; // Needs to be loaded first
import {startAPIServer, stopAPIServer} from './web'; // eslint-disable-line sort-imports
import {Browser} from 'puppeteer';
import {config} from './config';
import {getSleepTime} from './util';
import {logger} from './logger';
import puppeteer from 'puppeteer-extra';
+1 -1
View File
@@ -65,7 +65,7 @@ function generateTopic(link: Link, store: Store, topic: string): string {
/**
* Basic protection against sending credentials in the clear over public networks.
* - Returns 'true' if password is supplied in .env but address/URL is not part of a private network
* - Returns 'true' if password is supplied in dotenv but address/URL is not part of a private network
* - Private networks evaluated: Class A, B, or C private IP's or linklocal URL ("*.local")
* - TLS could be implemented, however, the majority of MQTT services on the internet do not require user authentication.
* - If you find a 'cloud' MQTT broker requiring authentication for publishing alerts, consider using another MQTT service (for now).