-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathssl.js
More file actions
39 lines (36 loc) · 869 Bytes
/
Copy pathssl.js
File metadata and controls
39 lines (36 loc) · 869 Bytes
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
const fs = require('fs')
const sslError = require('debug')('http2:error:ssl')
const {
key, cert, ssl
} = require('./options')
const readCertificates = () => {
try {
fs.statSync(key)
fs.statSync(cert)
} catch (e) {
sslError(`Certificates was not found: ${key} or ${cert}. Please review: https://github.com/slavaGanzin/http2-server#ssl-certificates`)
process.exit(0)
}
return Promise.resolve({
clientKey: fs.readFileSync(key, 'utf8'),
certificate: fs.readFileSync(cert, 'utf8')
})
}
const getOptions = ({certificate, clientKey}) => {
return {
key: clientKey,
cert: certificate,
ssl,
spdy: {
plain: !ssl,
},
agent: false,
strictSSL: false
}
}
module.exports =
(ssl
? readCertificates()
: Promise.resolve({certificate: null, clientKey: null}))
.then(getOptions)
.catch(sslError)