-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathroutesPro.js
96 lines (87 loc) · 2.41 KB
/
routesPro.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const proxy = require("express-http-proxy");
const serverFunctions = require("./lib/serverFunctions");
const SECTIONS = require("./constants/pro").SECTIONS;
module.exports = (app, server) => {
server.get("/", (req, res) => {
const actualPage = "/pro";
serverFunctions.renderAndCache(app, req, res, actualPage, req.query);
});
server.get(["/about", "/about-dpla-pro"], (req, res) => {
const actualPage = "/pro/wp";
const params = {
section: "about-dpla-pro"
}; // because WP has 'about-dpla-pro'
serverFunctions.renderAndCache(
app,
req,
res,
actualPage,
req.query,
params
);
});
// allow relative /news links in pro site
server.get(["/news/*", "/news"], (req, res) => {
var contentStart = req.url.indexOf("/news");
var newPath = process.env.USER_BASE_URL + req.url.substr(contentStart);
res.redirect(newPath);
});
// allow relative /search links in pro site
server.get("/search", (req, res) => {
var contentStart = req.url.indexOf("/search");
var newPath = process.env.USER_BASE_URL + req.url.substr(contentStart);
res.redirect(newPath);
});
// for hubs
server.get("/hubs", (req, res) => {
const actualPage = "/pro/wp/hubs";
serverFunctions.renderAndCache(app, req, res, actualPage, req.query);
});
// hubs subsections have regular page
server.get("/hubs/:subsection", (req, res) => {
const actualPage = "/pro/wp";
const params = {
section: req.params.section,
subsection: req.params.subsection
};
serverFunctions.renderAndCache(
app,
req,
res,
actualPage,
req.query,
params
);
});
// for non-hub top-level sections
SECTIONS.forEach(section => {
server.get("/" + section.slug, (req, res) => {
const actualPage = "/pro/wp";
const params = { section: section.slug };
serverFunctions.renderAndCache(
app,
req,
res,
actualPage,
req.query,
params
);
});
// when a top level section has subsections
server.get("/" + section.slug + "/:subsection", (req, res) => {
const actualPage = "/pro/wp";
const params = {
section: req.params.section,
subsection: req.params.subsection
};
serverFunctions.renderAndCache(
app,
req,
res,
actualPage,
req.query,
params
);
});
});
};