Skip to content

Commit

Permalink
👍 Add support for facebookincubator/create-react-app environment vari…
Browse files Browse the repository at this point in the history
…ables.
  • Loading branch information
OronNadiv committed Jan 16, 2018
1 parent 55c7afe commit 4fd2f83
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "home-automation-pubnub",
"version": "0.4.7",
"version": "0.5.0",
"description": "PubNub wrapper for the Home Automation project.",
"author": "Oron Nadiv <oron@nadiv.us> (https://github.com/OronNadiv/)",
"homepage": "https://github.com/OronNadiv/home-automation-pubnub/",
Expand All @@ -13,7 +13,7 @@
},
"license": "AGPL-3.0",
"engines": {
"node": ">=4 <9",
"node": ">=4 <10",
"npm": ">=2 <6"
},
"main": "dist/index.js",
Expand Down
22 changes: 14 additions & 8 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,35 @@ import DebugLib from 'debug'

const error = DebugLib('ha:pubnub:config:error')

export const publishKey = process.env.PUBNUB_PUBLISH_KEY
export const publishKey = process.env.PUBNUB_PUBLISH_KEY || process.env.REACT_APP_PUBNUB_PUBLISH_KEY
if (!publishKey) {
error('PubNub publish key could not be found in the environment variable. Please set \'PUBNUB_PUBLISH_KEY\'.')
if (process) {
const message = 'PubNub publish key could not be found in the environment variable. Please set \'PUBNUB_PUBLISH_KEY\' or \'REACT_APP_PUBNUB_PUBLISH_KEY\'.'
error(message)
if (process && process.exit) {
process.exit(100)
}
console.error(message)
}

export const subscribeKey = process.env.PUBNUB_SUBSCRIBE_KEY
export const subscribeKey = process.env.PUBNUB_SUBSCRIBE_KEY || process.env.REACT_APP_PUBNUB_SUBSCRIBE_KEY
if (!subscribeKey) {
error('PubNub subscribe key could not be found in the environment variable. Please set \'PUBNUB_SUBSCRIBE_KEY\'.')
if (process) {
const message = 'PubNub subscribe key could not be found in the environment variable. Please set \'PUBNUB_SUBSCRIBE_KEY\' or \'REACT_APP_PUBNUB_SUBSCRIBE_KEY\'.'
error(message)
if (process && process.exit) {
process.exit(200)
}
console.error(message)
}

export const secretKey = () => {
const res = process.env.PUBNUB_SECRET_KEY
if (!res) {
error('PubNub secret key could not be found in the environment variable. Please set \'PUBNUB_SECRET_KEY\'.')
if (process) {
const message = 'PubNub secret key could not be found in the environment variable. Please set \'PUBNUB_SECRET_KEY\'.'
error(message)
if (process && process.exit) {
process.exit(300)
}
console.error(message)
}
return res
}

0 comments on commit 4fd2f83

Please sign in to comment.