-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
62 lines (51 loc) · 1.61 KB
/
app.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const proxy = require("express-http-proxy");
const express = require("express");
const app = express();
const router = express.Router();
// Allow environment variables to be access through process.env
require("dotenv").config();
// Proxy requests to the local lambda functions server
app.use("/.netlify/functions", proxy("http://localhost:9000"));
// Map URLs to folders
app.use("/documents", express.static(`app/documents`));
app.use("/css", express.static(`app/css`));
app.use("/js", express.static(`app/js`));
app.use("/img", express.static(`app/img`));
app.use("/fonts", express.static(`app/fonts`));
app.use("/public", express.static(`app`));
app.set("views");
app.set("view engine", "pug");
app.use(router);
// Make sure all URLs use www.
router.all(/.*/, function(request, response, next) {
const host = request.get("host");
if (host === "robertcooper.me") {
if (host.match(/^www\..*/i)) {
next();
} else {
response.redirect(301, "https://www." + host);
}
}
next();
});
router.get("/", (request, response) => {
response.render("index", { environment: process.env.NODE_ENV });
});
router.get("/meat-journal-privacy-policy", (request, response) => {
response.render("meat-journal-privacy-policy", {
environment: process.env.NODE_ENV
});
});
app.use((request, response, next) => {
const err = new Error("Not Found");
err.status = 404;
next(err);
});
app.use((error, request, response) => {
response.status(error.status);
console.error(error.stack);
response.send(error.stack);
});
app.listen(8080, () => {
console.log("The application is running at http://localhost:8080!");
});