-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ssl): extract SSL into its own file (#295)
* feat(ssl): extract SSL into its own file Extract the ssl options into their own file, and add it to both servers. * fix(cypres bug): add `--tds` to cypres test server
- Loading branch information
1 parent
095e020
commit 6dd42a5
Showing
3 changed files
with
63 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import {readFileSync} from 'fs'; | ||
import https from 'https'; | ||
import selfsigned from 'selfsigned'; | ||
import {ssl, sslCert, sslKey} from '../utils/cli-options'; | ||
import {log, logError, yellow} from './log'; | ||
|
||
export function addSSL(server, host, port) { | ||
if (!ssl) { | ||
return server; | ||
} else { | ||
let pems = { | ||
private: '', | ||
cert: '', | ||
}; | ||
if (sslCert && sslKey) { | ||
try { | ||
pems.private = readFileSync(sslKey).toString(); | ||
pems.cert = readFileSync(sslCert).toString(); | ||
} catch (e) { | ||
logError(`Could not read the file: ${e.path}`); | ||
log(`${yellow(`Please check the path for the certificate.`)}`); | ||
process.exit(0); | ||
} | ||
} else { | ||
const attrs = [ | ||
{ | ||
name: 'scully', | ||
value: `${host}:${port}`, | ||
type: 'RSAPublicKey', | ||
}, | ||
]; | ||
pems = selfsigned.generate(attrs, {days: 365}); | ||
} | ||
// serve the API with signed certificate on 443 (SSL/HTTPS) port | ||
return https.createServer( | ||
{ | ||
key: pems.private, | ||
cert: pems.cert, | ||
}, | ||
server | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters