forked from jsonwebtoken/jsonwebtoken.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
47 lines (39 loc) · 1.16 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const express = require("express");
const enforce = require("express-sslify");
const languages = require("./libraries.json");
const dotenv = require("dotenv").config();
const app = express();
app.set("view engine", "pug");
app.set("views", __dirname + "/views/website");
if (process.env.NODE_ENV === "production") {
console.log("Redirecting to TLS endpoint.");
app.use(
enforce.HTTPS({
// Required for proper use under a reverse proxy (Heroku, etc.).
trustProtoHeader: true,
})
);
}
app.use((req, res, next) => {
res.locals.COOKIE_CONSENT_DOMAIN_ID = process.env.COOKIE_CONSENT_DOMAIN_ID;
next();
});
app.use(express.static("dist/website"));
app.get("/", function(req, res) {
res.render("index");
});
app.get("/introduction", function(req, res) {
res.render("introduction");
});
app.get("/libraries", function(req, res) {
res.render("libraries", {
languages: languages
});
});
// Fallback for the homepage JWT handbook CTA A/B experiment we ran
app.get("/home", function(req, res) {
res.redirect("/");
});
app.listen(process.env.PORT || 3000, function() {
console.log("Started.");
});