From dc4675e1dc601842588c61188b9cb0f269eccd4f Mon Sep 17 00:00:00 2001 From: Stefan Thomas Date: Mon, 22 Feb 2016 11:12:19 -0800 Subject: [PATCH] Turn ensureLeadingSlash into a function --- lib/config.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/config.js b/lib/config.js index 552776a..c555b6e 100644 --- a/lib/config.js +++ b/lib/config.js @@ -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. * @@ -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'