Skip to content

Commit

Permalink
refactor: refactor the app config file
Browse files Browse the repository at this point in the history
  • Loading branch information
simplymichael committed Jun 21, 2024
1 parent 0b43dd8 commit 3ef4b2d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/config/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,26 @@ const string = require("../framework/lib/string");
const SPLIT_REGEX = /[\s+,;|]+/;
const APP_ROOT = string.convertBackSlashToForwardSlash(path.resolve(path.dirname(__dirname), ".."));
const APP_SRC_DIR = `${APP_ROOT}/src`;
const HTTP_REGEX = /^https?:\/\//i;

let host = env.HOST;
let port = env.PORT;
let scheme = env.URL_SCHEME?.toLowerCase();

if(!(/^https?(:\/\/)?/.test(scheme))) {
scheme = "http://";
}

scheme = scheme.split(/:\/\//)[0] + "://";
host = (HTTP_REGEX.test(host)) ? host: `${scheme}${host}`;
port = [80, 443].includes(Number(port)) ? "" : port;

module.exports = {
name : env.NAME,
host : env.HOST,
port : env.PORT,
url : port ? `${host}:${port}` : host,
urlScheme : scheme,
environment : (env.NODE_ENV || "production").toLowerCase(),
apiVersion : env.API_VERSION,
debug : is.falsy(env.DEBUG?.trim()?.toLowerCase()) ? false : true,
Expand Down

0 comments on commit 3ef4b2d

Please sign in to comment.