Skip to content

Commit

Permalink
chore(heroku): extract BASE_URL parsing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jlegrone committed Mar 21, 2019
1 parent 99af95b commit a9b6e73
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
web: npm start
web: npm run start:heroku
jobhandler: npm run prod-job-handler
messagesender01: npm run prod-message-sender-01
messagesender234: npm run prod-message-sender-234
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"postinstall": "if [ \"$NODE_ENV\" = production ] ; then npm run prod-build && npm run prod-static-upload && npm run notify-slack; fi",
"notify-slack": "if [ \"$SLACK_NOTIFY_URL\" != \"\" ] ; then echo notifying slack && curl -XPOST -d '{\"channel\": \"#spoke\", \"text\":\"'\"$(whoami) building spoke $(git log -1 --pretty=%h) for $AWS_S3_BUCKET_NAME\"'\"}' $SLACK_NOTIFY_URL; fi",
"start": "node ./build/server/server",
"start:heroku": "BASE_URL=$(node ./build/server/heroku/print-base-url) npm start",
"dev-message-sender-01": "nodemon -e js,jsx -w ./src --exec ./dev-tools/babel-run -- ./src/workers/message-sender-01",
"prod-message-sender-01": "./dev-tools/babel-run ./src/workers/message-sender-01.js",
"dev-message-sender-234": "nodemon -e js,jsx -w ./src --exec ./dev-tools/babel-run -- ./src/workers/message-sender-234",
Expand Down
7 changes: 7 additions & 0 deletions src/heroku/print-base-url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
if (process.env.BASE_URL) {
console.log(process.env.BASE_URL)
} else if (process.env.HEROKU_APP_NAME) {
console.log(`https://${process.env.HEROKU_APP_NAME}.herokuapp.com`)
} else {
throw new Error('Neither BASE_URL nor HEROKU_APP_NAME environment variables are present.')
}
8 changes: 0 additions & 8 deletions src/lib/parse-base-url.js

This file was deleted.

3 changes: 1 addition & 2 deletions src/server/auth-passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import { Strategy as LocalStrategy } from 'passport-local'
import { userLoggedIn } from './models/cacheable_queries'
import { User } from './models'
import wrap from './wrap'
import parseBaseURL from '../lib/parse-base-url'

export function setupAuth0Passport() {
const strategy = new Auth0Strategy({
domain: process.env.AUTH0_DOMAIN,
clientID: process.env.AUTH0_CLIENT_ID,
clientSecret: process.env.AUTH0_CLIENT_SECRET,
callbackURL: `${parseBaseURL()}/login-callback`
callbackURL: `${process.env.BASE_URL}/login-callback`
}, (accessToken, refreshToken, extraParams, profile, done) => done(null, profile)
)

Expand Down
4 changes: 1 addition & 3 deletions src/server/middleware/render-index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import parseBaseURL from '../../lib/parse-base-url'

const rollbarScript = process.env.ROLLBAR_CLIENT_TOKEN ?
`<script>
var _rollbarConfig = {
Expand Down Expand Up @@ -67,7 +65,7 @@ export default function renderIndex(html, css, assetMap, store) {
window.SUPPRESS_SELF_INVITE="${process.env.SUPPRESS_SELF_INVITE || ''}"
window.NODE_ENV="${process.env.NODE_ENV}"
window.PRIVACY_URL="${process.env.PRIVACY_URL || ''}"
window.BASE_URL="${parseBaseURL()}"
window.BASE_URL="${process.env.BASE_URL || ''}"
window.NOT_IN_USA=${process.env.NOT_IN_USA || 0}
window.ALLOW_SEND_ALL=${process.env.ALLOW_SEND_ALL || 0}
window.BULK_SEND_CHUNK_SIZE=${process.env.BULK_SEND_CHUNK_SIZE || 0}
Expand Down

0 comments on commit a9b6e73

Please sign in to comment.