diff --git a/api.js b/api.js index 7caf844..17df1ac 100644 --- a/api.js +++ b/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(); diff --git a/env.js b/env.js new file mode 100644 index 0000000..8999dd4 --- /dev/null +++ b/env.js @@ -0,0 +1,9 @@ +module.exports = { + getEnvVar: function (varname, defaultvalue){ + var result = process.env[varname]; + if(result!=undefined) + return result; + else + return defaultvalue; + } +};