Last active
February 27, 2022 05:43
-
-
Save tadeaspetak/be370d48d9e995adfdc099b5bc542587 to your computer and use it in GitHub Desktop.
Front & Fullstack Security
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
import express from "express"; | |
import fs from "fs"; | |
import helmet from "helmet"; | |
import https from "https"; | |
import path from "path"; | |
const app = express(); | |
// avoid having to manually tweak CSP, HSTS, X-Powered-By, MIME-sniffing, etc.; set the strictest CSP possible | |
app.use(helmet({ contentSecurityPolicy: { directives: { defaultSrc: "'self'" } } })); | |
app.use(express.json()); | |
const client = path.resolve(__dirname, "../build"); | |
if (fs.existsSync(client)) app.use(express.static(client)); | |
app.get("/healthz", (_, res) => { res.send({ message: "We're live 🚀" }); }); | |
const httpsOptions = { | |
key: fs.readFileSync(path.join(__dirname, "./tls/cert.key")), | |
cert: fs.readFileSync(path.join(__dirname, "./tls/cert.pem")), | |
}; | |
const portHttps = process.env.PORT_HTTPS || 8080; | |
https.createServer(httpsOptions, app).listen(portHttps, async () => { | |
console.log(`HTTPS server listening at ${portHttps}`); // eslint-disable-line no-console | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment