Skip to content

Commit

Permalink
fix: use env_prefix dev_server param in dev_server.js (#1858)
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan authored and gauravtiwari committed Jan 3, 2019
1 parent 9ea3b43 commit a9c8979
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
15 changes: 15 additions & 0 deletions package/__tests__/dev_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ describe('DevServer', () => {
expect(devServer.port).toEqual('5000')
})

test('with custom env prefix', () => {
const config = require('../config')
config.dev_server.env_prefix = 'TEST_WEBPACKER_DEV_SERVER_'

process.env.NODE_ENV = 'development'
process.env.RAILS_ENV = 'development'
process.env.TEST_WEBPACKER_DEV_SERVER_HOST = '0.0.0.0'
process.env.TEST_WEBPACKER_DEV_SERVER_PORT = 5000

const devServer = require('../dev_server')
expect(devServer).toBeDefined()
expect(devServer.host).toEqual('0.0.0.0')
expect(devServer.port).toEqual('5000')
})

test('with NODE_ENV and RAILS_ENV set to production', () => {
process.env.RAILS_ENV = 'production'
process.env.NODE_ENV = 'production'
Expand Down
4 changes: 3 additions & 1 deletion package/dev_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ const fetch = (key) => {
const devServerConfig = config.dev_server

if (devServerConfig) {
const envPrefix = config.dev_server.env_prefix || 'WEBPACKER_DEV_SERVER_'

Object.keys(devServerConfig).forEach((key) => {
const envValue = fetch(`WEBPACKER_DEV_SERVER_${key.toUpperCase().replace(/_/g, '')}`)
const envValue = fetch(`${envPrefix}${key.toUpperCase().replace(/_/g, '')}`)
if (envValue !== undefined) devServerConfig[key] = envValue
})
}
Expand Down

0 comments on commit a9c8979

Please sign in to comment.