aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/core-utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/core-utils.ts')
-rw-r--r--server/helpers/core-utils.ts22
1 files changed, 22 insertions, 0 deletions
diff --git a/server/helpers/core-utils.ts b/server/helpers/core-utils.ts
index 443115336..0c6c36d11 100644
--- a/server/helpers/core-utils.ts
+++ b/server/helpers/core-utils.ts
@@ -11,6 +11,26 @@ import * as mkdirp from 'mkdirp'
11import { join } from 'path' 11import { join } from 'path'
12import * as pem from 'pem' 12import * as pem from 'pem'
13import * as rimraf from 'rimraf' 13import * as rimraf from 'rimraf'
14import { URL } from 'url'
15
16function sanitizeUrl (url: string) {
17 const urlObject = new URL(url)
18
19 if (urlObject.protocol === 'https:' && urlObject.port === '443') {
20 urlObject.port = ''
21 } else if (urlObject.protocol === 'http:' && urlObject.port === '80') {
22 urlObject.port = ''
23 }
24
25 return urlObject.href.replace(/\/$/, '')
26}
27
28// Don't import remote scheme from constants because we are in core utils
29function sanitizeHost (host: string, remoteScheme: string) {
30 let toRemove = remoteScheme === 'https' ? 443 : 80
31
32 return host.replace(new RegExp(`:${toRemove}$`), '')
33}
14 34
15function isTestInstance () { 35function isTestInstance () {
16 return process.env.NODE_ENV === 'test' 36 return process.env.NODE_ENV === 'test'
@@ -114,6 +134,8 @@ export {
114 root, 134 root,
115 escapeHTML, 135 escapeHTML,
116 pageToStartAndCount, 136 pageToStartAndCount,
137 sanitizeUrl,
138 sanitizeHost,
117 139
118 promisify0, 140 promisify0,
119 promisify1, 141 promisify1,