Skip to content

Commit 1a75e89

Browse files
committed
Enable SSL.
1 parent 330adcc commit 1a75e89

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

copyStaticAssets.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
import * as shell from "shelljs";
2+
import fs from "fs";
23

34
shell.cp("-R", "src/public/fonts", "dist/public/");
45
shell.cp("-R", "src/public/images", "dist/public/");
6+
7+
if (shell.ls('localhost.crt').length == 0) {
8+
shell.exec('openssl req \
9+
-new \
10+
-newkey rsa:4096 \
11+
-days 365 \
12+
-nodes \
13+
-x509 \
14+
-subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=localhost" \
15+
-keyout localhost.key \
16+
-out localhost.crt');
17+
}

src/app.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,22 @@ import bluebird from "bluebird";
1010
import cors from "cors";
1111

1212
// Create Express server
13-
//
1413
const app = express();
1514

15+
if (["development", "staging", "production"].indexOf(process.env.NODE_ENV) == -1) {
16+
const https = require('https');
17+
18+
// SSL
19+
const sslkey = fs.readFileSync("localhost.key");
20+
const sslcert = fs.readFileSync("localhost.crt");
21+
const options = {
22+
key: sslkey,
23+
cert: sslcert
24+
};
25+
26+
https.createServer(options, app).listen(443);
27+
}
28+
1629
// Express configuration
1730
//
1831
app.set("port", process.env.PORT || 8000);

0 commit comments

Comments
 (0)