forked from coralproject/talk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
url.js
29 lines (23 loc) · 861 Bytes
/
url.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const {
ROOT_URL,
ROOT_URL_MOUNT_PATH,
STATIC_URI,
} = require('./config');
const {URL} = require('url');
const trailingSlash = (url) => url && url.length > 0 && url[url.length - 1] === '/' ? url : `${url}/`;
// Set the BASE_URL as the ROOT_URL, here we derive the root url by ensuring
// that it ends in a `/`.
const BASE_URL = trailingSlash(ROOT_URL);
// The BASE_PATH is simply the path component of the BASE_URL.
const BASE_PATH = new URL(BASE_URL).pathname;
// The MOUNT_PATH is derived from the BASE_PATH, if it is provided and enabled.
// This will mount all the application routes onto it.
const MOUNT_PATH = ROOT_URL_MOUNT_PATH ? BASE_PATH : '/';
// The STATIC_URL is the url where static assets should be loaded from.
const STATIC_URL = trailingSlash(STATIC_URI);
module.exports = {
BASE_URL,
BASE_PATH,
MOUNT_PATH,
STATIC_URL,
};