Skip to content

Commit 5696fb8

Browse files
author
Simon Hampton
committed
merge
2 parents eca99a5 + 4a840df commit 5696fb8

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ HTTPS can be enabled (using a generated self-signed certificate) with `--https`
3636
angular-http-server --https
3737
```
3838

39+
You may manually specify the paths to your self-signed certificate using the `--key` and `--cert` flags
40+
41+
```sh
42+
angular-http-server --https --key ./secret/key.pem --cert ./secret/cert.pem
43+
```
44+
3945
[CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS) can be enabled with the --cors flag
4046

4147
```sh

angular-http-server.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ var https = require("https");
99
var http = require("http");
1010
var opn = require("opn");
1111

12-
const useHttps = argv.ssl || argv.https;
13-
14-
var server;
1512

1613
const NO_PATH_FILE_ERROR_MESSAGE =
1714
"Error: index.html could not be found in the specified path ";
@@ -37,20 +34,35 @@ if (argv.config) {
3734
argv = Object.assign({}, config, argv);
3835
}
3936

37+
const useHttps = argv.ssl || argv.https;
38+
4039
// As a part of the startup - check to make sure we can access index.html
4140
returnDistFile(true);
4241

43-
// Start with with/without https
42+
// Start with/without https
43+
let server;
4444
if (useHttps) {
45-
pem.createCertificate({ days: 1, selfSigned: true }, function(err, keys) {
46-
var options = {
45+
const startSSLCallback = (err, keys) => {
46+
if (err) {
47+
throw err;
48+
}
49+
50+
const options = {
4751
key: keys.serviceKey,
4852
cert: keys.certificate,
4953
rejectUnauthorized: false
5054
};
5155
server = https.createServer(options, requestListener);
5256
start();
53-
});
57+
};
58+
59+
if (argv.key && argv.cert) {
60+
const serviceKey = fs.readFileSync(argv.key);
61+
const certificate = fs.readFileSync(argv.cert);
62+
startSSLCallback(null, { serviceKey, certificate });
63+
} else {
64+
pem.createCertificate({ days: 1, selfSigned: true }, startSSLCallback);
65+
}
5466
} else {
5567
server = http.createServer(requestListener);
5668
start();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
}
2929
],
3030
"engines": {
31-
"node": ">=6.0.0"
31+
"node": ">=8.0.0"
3232
},
3333
"preferGlobal": true,
3434
"bin": {

0 commit comments

Comments
 (0)