Skip to content

Commit

Permalink
Turn ensureLeadingSlash into a function
Browse files Browse the repository at this point in the history
  • Loading branch information
justmoon committed Feb 22, 2016
1 parent 6d27922 commit dc4675e
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ function removeEmpty (obj) {
return _.omit(obj, _.isEmpty)
}

function ensureLeadingSlash (path) {
return path.length && path[0] !== '/' ? '/' + path : path
}

/**
* Parse a boolean config variable.
*
Expand Down Expand Up @@ -78,12 +82,7 @@ function parseServerConfig (prefix) {
let port = parseInt(getEnv(prefix, 'PORT'), 10) || 3000
let public_host = getEnv(prefix, 'HOSTNAME') || require('os').hostname()
let public_port = parseInt(getEnv(prefix, 'PUBLIC_PORT'), 10) || port
let public_path = getEnv(prefix, 'PUBLIC_PATH') || ''

// Ensure path starts with a slash
if (public_path.length && public_path[0] !== '/') {
public_path = '/' + public_path
}
const public_path = ensureLeadingSlash(getEnv(prefix, 'PUBLIC_PATH') || '')

if (useTestConfig()) {
public_host = 'localhost'
Expand Down

0 comments on commit dc4675e

Please sign in to comment.