Skip to content

Commit 6fe6809

Browse files
committed
fix: Prevent the active environment to be set up in the start script of the package.json. Replace that with the now.json's env.active property or default to 'default'
1 parent 9126492 commit 6fe6809

File tree

2 files changed

+2
-36
lines changed

2 files changed

+2
-36
lines changed

src/index.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const fs = require('fs')
99
const shortid = require('shortid')
1010
const path = require('path')
1111
const { getRouteDetails, matchRoute } = require('./routing')
12-
const { reqUtil, pkgJson } = require('./utils')
12+
const { reqUtil } = require('./utils')
1313
require('colors')
1414

1515
/*eslint-disable */
@@ -61,16 +61,11 @@ let _allowedMethods = getAllowedMethods(_config) // Object
6161
let _preEvent = () => Promise.resolve(null)
6262
let _postEvent = () => Promise.resolve(null)
6363

64-
// This guarentees that any environment variables defined in the package.json's start scripts get assigned even
65-
// if the package.json's start script is not executed (which is the case with FaaS like Google Cloud Functions
66-
// or AWS Lambda)
67-
pkgJson.initStartVariables()
68-
6964
//////////////////////// END - INITIALIZE APP ////////////////////////
7065
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7166
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7267

73-
const getEnvName = () => ((_config || {}).env || {}).active || getProcessEnv().WEBFUNC_ENV || 'default'
68+
const getEnvName = () => ((_config || {}).env || {}).active || 'default'
7469
const getEnv = () => ((_config || {}).env || {})[getEnvName()] || {}
7570
const getHostingType = () => getEnv().hostingType || 'localhost'
7671

src/utils.js

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -95,37 +95,8 @@ const getParams = req => {
9595
})
9696
}
9797

98-
const initStartVariables = () => {
99-
try {
100-
const pkg = require(cwdPath('package.json')) || {}
101-
if (pkg.scripts && pkg.scripts.start)
102-
(pkg.scripts.start.trim()).split(' ')
103-
.filter(x => x)
104-
.map(x => x.split('='))
105-
.filter(x => x.length == 2)
106-
.forEach(x => {
107-
/*eslint-disable */
108-
if (x[0] != 'NODE_ENV')
109-
process.env[x[0]] = x[1]
110-
else
111-
process.env.WEBFUNC_ENV = x[1]
112-
/*eslint-enable */
113-
})
114-
/*eslint-disable */
115-
if (!process.env.WEBFUNC_ENV && process.env.NODE_ENV)
116-
process.env.WEBFUNC_ENV = process.env.NODE_ENV
117-
/*eslint-enable */
118-
}
119-
catch(err) {
120-
console.error(err.message)
121-
}
122-
}
123-
12498
module.exports = {
12599
reqUtil: {
126100
getParams
127-
},
128-
pkgJson: {
129-
initStartVariables
130101
}
131102
}

0 commit comments

Comments
 (0)