Secure server

This commit is contained in:
fkereki
2018-05-14 23:19:12 -04:00
parent bacc913803
commit b7eacc08e0
6 changed files with 148 additions and 1 deletions
+5 -1
View File
@@ -6,4 +6,8 @@ const app = express();
app.get("/", (req, res) => res.send("Server alive, with Express!"));
app.listen(8080, () => console.log("Mini server (with Express) ready at http://localhost:8080/!"));
app.listen(8080, () =>
console.log(
"Mini server (with Express) ready at http://localhost:8080/!"
)
);
+18
View File
@@ -0,0 +1,18 @@
/* @flow */
"use strict";
const express = require("express");
const app = express();
const http = require("http");
http.createServer(app).listen(8080);
app.use((req, res, next) => {
if (req.secure) {
next();
} else {
res.redirect(
`https://${req.headers.host.replace(/8080/, "8443")}${req.url}`
);
}
});
+17
View File
@@ -0,0 +1,17 @@
/* @flow */
"use strict";
const express = require("express");
const app = express();
const https = require("https");
const fs = require("fs");
const path = require("path");
const keysPath = path.join(__dirname, "../../certificates");
const ca = fs.readFileSync(`${keysPath}/modernjsbook.csr`);
const cert = fs.readFileSync(`${keysPath}/modernjsbook.crt`);
const key = fs.readFileSync(`${keysPath}/modernjsbook.key`);
https.createServer({ ca, cert, key }, app).listen(8443);
app.get("/", (req, res) => res.send("Secure server!"));