Secure server
This commit is contained in:
@@ -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/!"
|
||||
)
|
||||
);
|
||||
|
||||
@@ -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}`
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -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!"));
|
||||
Reference in New Issue
Block a user