-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutils.js
More file actions
45 lines (42 loc) · 1.09 KB
/
Copy pathutils.js
File metadata and controls
45 lines (42 loc) · 1.09 KB
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
export function hostname(c) {
let req = c.request
let h = req.headers.get('x-forwarded-host') || req.headers.get('host')
if (h) {
h = h.split(':')[0] // remove port
}
return h
}
export function hostURL(c) {
let h = hostname(c)
if (!h) return ''
if (h.includes('localhost') || h.includes('127.0.0.1')) {
let req = c.request
let h2 = req.headers.get('x-forwarded-host') || req.headers.get('host')
let port = ''
if (h2) {
let split = h2.split(':')
if (split.length > 1) {
port = `:${split[1]}`
}
}
return `http://${h}${port}`
}
h = 'https://' + h
return h
}
export function domainLevels(c) {
const host = hostname(c)
if (!host) return 2
return host.endsWith('.workers.dev') || host.endsWith('.pages.dev') ? 3 : 2
}
export async function awaitAll(c, promises) {
let results = await Promise.allSettled(promises)
// c.data.logger.log('awaitAll results:', results)
for (let r of results) {
// c.data.logger.log(r)
if (r.status == 'rejected') {
console.log(`awaitAll error:`, r.reason)
throw r.reason
}
}
}