-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
65 lines (54 loc) · 1.46 KB
/
index.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
const express = require('express');
const port = process.env.PORT || 3000;
const app = express();
const util = require('util')
app.use('/_assets', express.static(__dirname + '/_assets'));
app.use('/visualquiz', express.static(__dirname + '/visualquiz'));
// set the view engine to ejs
app.set('view engine', 'ejs');
// load in the json file for creating dynamic pages
var fs = require('fs');
var content = JSON.parse(fs.readFileSync("pages.json", 'utf8'));
const entries = Object.entries(content);
for (const [obj, handle] of entries) {
// dynamic pages
app.get("/"+handle.url, function(req, res) {
res.render('pages/dynamic', {
pagecontent: handle
});
});
}
// our index and confirmation pages need some basic info passed through because the partials use them
app.get("/", function(req, res) {
var cc = {
"title": "Testing Platform"
}
res.render('pages/index', {
pagecontent: cc
});
});
app.get("/beera", function(req, res) {
var cc = {
"title": "Testing Platform - Beer A"
}
res.render('pages/dynamic_beer_a', {
pagecontent: cc
});
});
app.get("/beerb", function(req, res) {
var cc = {
"title": "Testing Platform - Beer B"
}
res.render('pages/dynamic_beer_b', {
pagecontent: cc
});
});
app.get("/redirect", function(req, res) {
var cc = {
"title": "Redirect"
}
res.render('pages/redirect', {
pagecontent: cc
});
});
app.listen(port, () => console.log(`CPB TestTestTestDotCom listening on port ${port}!`))