-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathindex.js
47 lines (47 loc) · 1.18 KB
/
index.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
37
38
39
40
41
42
43
44
45
46
47
'use strict'
exports.__esModule = true
function absoluteUrl(req, localhostAddress) {
if (localhostAddress === void 0) {
localhostAddress = 'localhost:3000'
}
var _a
var host =
(((_a = req) === null || _a === void 0
? void 0
: _a.headers)
? req.headers.host
: window.location.host) || localhostAddress
var protocol = isLocalNetwork(host) ? 'http:' : 'https:'
if (
req &&
req.headers['x-forwarded-host'] &&
typeof req.headers['x-forwarded-host'] === 'string'
) {
host = req.headers['x-forwarded-host'].split(',')[0]
}
if (
req &&
req.headers['x-forwarded-proto'] &&
typeof req.headers['x-forwarded-proto'] === 'string'
) {
protocol = req.headers['x-forwarded-proto'].split(',')[0] + ':'
}
return {
protocol: protocol,
host: host,
origin: protocol + '//' + host,
}
}
function isLocalNetwork(hostname) {
if (hostname === void 0) {
hostname = window.location.host
}
return (
hostname.startsWith('localhost') ||
hostname.startsWith('127.0.0.1') ||
hostname.startsWith('192.168.') ||
hostname.startsWith('10.0.') ||
hostname.endsWith('.local')
)
}
exports['default'] = absoluteUrl