-
-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #138 from timoschlueter/release/2.6.0
Release 2.6.0
- Loading branch information
Showing
7 changed files
with
153 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.git* | ||
README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,87 @@ | ||
function readConfig() { | ||
const requiredEnvs = ['NIGHTSCOUT_API_TOKEN', 'NIGHTSCOUT_URL']; | ||
for (let envName of requiredEnvs) { | ||
if (!process.env[envName]) { | ||
throw Error(`Required environment variable ${envName} is not set`); | ||
} | ||
} | ||
|
||
const protocol = | ||
process.env.NIGHTSCOUT_DISABLE_HTTPS === 'true' ? 'http://' : 'https://'; | ||
const url = new URL(protocol + process.env.NIGHTSCOUT_URL); | ||
|
||
return { | ||
nightscoutApiToken: process.env.NIGHTSCOUT_API_TOKEN as string, | ||
nightscoutBaseUrl: url.toString(), | ||
|
||
nightscoutApiV3: process.env.NIGHTSCOUT_API_V3 === 'true', | ||
nightscoutDevice: process.env.DEVICE_NAME || 'nightscout-librelink-up', | ||
}; | ||
import {LLU_API_ENDPOINTS} from './constants/llu-api-endpoints'; | ||
|
||
function readConfig() | ||
{ | ||
let requiredEnvs: string[] = []; | ||
|
||
if (!isTest()) | ||
{ | ||
requiredEnvs = [ | ||
'NIGHTSCOUT_API_TOKEN', | ||
'NIGHTSCOUT_URL', | ||
'LINK_UP_USERNAME', | ||
'LINK_UP_PASSWORD', | ||
]; | ||
} | ||
|
||
for (let envName of requiredEnvs) | ||
{ | ||
if (!process.env[envName]) | ||
{ | ||
exitLog(`Required environment variable ${envName} is not set`) | ||
} | ||
} | ||
|
||
if (process.env.LOG_LEVEL) | ||
{ | ||
if (!['info', 'debug'].includes(process.env.LOG_LEVEL.toLowerCase())) | ||
{ | ||
exitLog(`LOG_LEVEL should be either 'info' or 'debug', but got '${process.env.LOG_LEVEL}'`); | ||
} | ||
} | ||
|
||
if (process.env.LINK_UP_REGION) | ||
{ | ||
if (!LLU_API_ENDPOINTS.hasOwnProperty(process.env.LINK_UP_REGION)) | ||
{ | ||
exitLog(`LINK_UP_REGION should be one of ${Object.keys(LLU_API_ENDPOINTS)}, but got ${process.env.LINK_UP_REGION}`); | ||
} | ||
} | ||
|
||
if (process.env.LINK_UP_TIME_INTERVAL) | ||
{ | ||
if (isNaN(parseInt(process.env.LINK_UP_TIME_INTERVAL))) | ||
{ | ||
exitLog(`LINK_UP_TIME_INTERVAL expected to be an integer, but got '${process.env.LINK_UP_TIME_INTERVAL}'`); | ||
} | ||
} | ||
|
||
const protocol = | ||
process.env.NIGHTSCOUT_DISABLE_HTTPS === 'true' ? 'http://' : 'https://'; | ||
const url = new URL(protocol + process.env.NIGHTSCOUT_URL); | ||
|
||
return { | ||
nightscoutApiToken: process.env.NIGHTSCOUT_API_TOKEN as string, | ||
nightscoutBaseUrl: url.toString(), | ||
linkUpUsername: process.env.LINK_UP_USERNAME as string, | ||
linkUpPassword: process.env.LINK_UP_PASSWORD as string, | ||
|
||
logLevel: process.env.LOG_LEVEL || 'info', | ||
singleShot: process.env.SINGLE_SHOT === 'true', | ||
|
||
nightscoutApiV3: process.env.NIGHTSCOUT_API_V3 === 'true', | ||
nightscoutDisableHttps: process.env.NIGHTSCOUT_DISABLE_HTTPS === 'true', | ||
nightscoutDevice: process.env.DEVICE_NAME || 'nightscout-librelink-up', | ||
|
||
linkUpRegion: process.env.LINK_UP_REGION || 'EU', | ||
linkUpTimeInterval: Number(process.env.LINK_UP_TIME_INTERVAL) || 5, | ||
linkUpConnection: process.env.LINK_UP_CONNECTION as string, | ||
}; | ||
} | ||
|
||
function exitLog(msg: string): void | ||
{ | ||
console.log(msg); | ||
|
||
if (!isTest()) | ||
{ | ||
process.exit(1); | ||
} | ||
} | ||
|
||
function isTest(): boolean | ||
{ | ||
return typeof jest !== "undefined"; | ||
} | ||
|
||
export default readConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters