function to read from env
This commit is contained in:
parent
21711b960c
commit
d13b5933d0
2 changed files with 11 additions and 1 deletions
3
api.js
3
api.js
|
|
@ -1,9 +1,10 @@
|
|||
const got = require('got');
|
||||
const { getEnvVar } = require('./env.js');
|
||||
|
||||
const fetchEvents = () =>
|
||||
got('http://localhost:8384/rest/events', {
|
||||
headers: {
|
||||
'X-API-Key': process.env.API_KEY,
|
||||
'X-API-Key': getEnvVar('API_KEY','invalid')
|
||||
},
|
||||
}).json();
|
||||
|
||||
|
|
|
|||
9
env.js
Normal file
9
env.js
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
module.exports = {
|
||||
getEnvVar: function (varname, defaultvalue){
|
||||
var result = process.env[varname];
|
||||
if(result!=undefined)
|
||||
return result;
|
||||
else
|
||||
return defaultvalue;
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue