-
Notifications
You must be signed in to change notification settings - Fork 16
/
constructAppUrl.js
36 lines (29 loc) · 1.19 KB
/
constructAppUrl.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
30
31
32
33
34
35
36
const formatUrlSafeAppSlug = (appName) => {
return appName.replace(/[^A-Za-z0-9\s-]/g, '').replace(/\s+/g, '-')
}
const constructAppUrl = (baseUrl, config, serverVersion) => {
let appUrl = baseUrl
const isModernServer = serverVersion.major >= 2 && serverVersion.minor >= 35
// From core version 2.35, short_name is used instead of the human-readable title to generate the url slug
const urlSafeAppSlug = formatUrlSafeAppSlug(
isModernServer ? config.name : config.title
)
// From core version 2.35, core apps are hosted at the server root under the /dhis-web-* namespace
if (config.coreApp && isModernServer) {
appUrl += `/dhis-web-${urlSafeAppSlug}/`
} else {
appUrl += `/api/apps/${urlSafeAppSlug}/`
}
// Prior to core version 2.35, installed applications did not properly serve "pretty" urls (`/` vs `/index.html`)
if (!isModernServer) {
appUrl += 'index.html'
}
// Clean up any double slashes
const scheme = appUrl.substr(0, appUrl.indexOf(':https://') + 3)
appUrl = scheme + appUrl.substr(scheme.length).replace(/\/+/g, '/')
return appUrl
}
module.exports = {
constructAppUrl,
formatUrlSafeAppSlug,
}