-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathgetOriginConfig.js
42 lines (37 loc) · 1.05 KB
/
getOriginConfig.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
const url = require('url')
module.exports = (origin, { originAccessIdentityId = '' }) => {
const originUrl = typeof origin === 'string' ? origin : origin.url
const { hostname, pathname } = url.parse(originUrl)
const originConfig = {
Id: hostname,
DomainName: hostname,
CustomHeaders: {
Quantity: 0,
Items: []
},
OriginPath: pathname === '/' ? '' : pathname
}
if (originUrl.includes('s3')) {
const bucketName = hostname.split('.')[0]
originConfig.Id = bucketName
originConfig.DomainName = `${bucketName}.s3.amazonaws.com`
originConfig.S3OriginConfig = {
OriginAccessIdentity: originAccessIdentityId
? `origin-access-identity/cloudfront/${originAccessIdentityId}`
: ''
}
} else {
originConfig.CustomOriginConfig = {
HTTPPort: 80,
HTTPSPort: 443,
OriginProtocolPolicy: 'https-only',
OriginSslProtocols: {
Quantity: 1,
Items: ['TLSv1.2']
},
OriginReadTimeout: 30,
OriginKeepaliveTimeout: 5
}
}
return originConfig
}