-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
149 lines (122 loc) · 4.09 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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
require('dotenv').config();
const path = require("path");
const express = require("express");
const https = require('https')
const http = require('http');
const fs = require('fs')
const compression = require('compression');
const helmet = require('helmet');
const robots = require('express-robots-txt');
const expressSitemapXml = require('express-sitemap-xml')
const app = express();
app.use(helmet());
app.use(robots({UserAgent: '*', Disallow: '/public/media', CrawlDelay: '120', Sitemap: 'http://justcatalyst.org/sitemap.xml'}))
app.use(expressSitemapXml(getUrls, 'http://justcatalyst.org/sitemap.xml'))
async function getUrls () {
return await getUrlsFromDatabase()
}
const httpPort = process.env.HTTP || "8082";
const httpsPort = process.env.HTTPS || "4423";
///////////////////// VIEWS /////////////////////
app.use(compression()); //Compress all routes
app.use(express.static(path.join(__dirname, "public")));
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "pug");
app.get("/", (req, res) => {
res.render("index", { title: "Home" });
});
app.get("/expertise", (req, res) => {
res.render("expertise", { title: "Expertise" });
});
app.get("/projects", (req, res) => {
res.render("projects", { title: "Projects" });
});
app.get("/contact", (req, res) => {
res.render("contact", { title: "Contact" });
});
app.get("/pod", (req, res) => {
res.render("pod", { title: "Print on demand" });
});
app.get("/manufacturing", (req, res) => {
res.render("manufacturing", { title: "Manufacturing" });
});
app.get("/cosmetics", (req, res) => {
res.render("cosmetics", { title: "Cosmetics" });
});
app.get("/fitness", (req, res) => {
res.render("fitness", { title: "Fitness" });
});
app.get("/web-q", (req, res) => {
res.render("web-q", { title: "Web Questionnaire" });
});
app.get("/pod-q", (req, res) => {
res.render("pod-q", { title: "POD Questionnaire" });
});
app.get("/brand-values", (req, res) => {
res.render("brand-values", { title: "Brand Values" });
});
app.get("/sitemap.xml", (req, res) => {
res.render("sitemap", { title: "sitemap" });
});
// Load video file
app.get('/video', function(req, res) {
const path = 'public/media/fitness-bg.webm'
const stat = fs.statSync(path)
const fileSize = stat.size
const range = req.headers.range
if (range) {
const parts = range.replace(/bytes=/, "").split("-")
const start = parseInt(parts[0], 10)
const end = parts[1]
? parseInt(parts[1], 10)
: fileSize-1
if(start >= fileSize) {
res.status(416).send('Requested range not satisfiable\n'+start+' >= '+fileSize);
return
}
const chunksize = (end-start)+1
const file = fs.createReadStream(path, {start, end})
const head = {
'Content-Range': `bytes ${start}-${end}/${fileSize}`,
'Accept-Ranges': 'bytes',
'Content-Length': chunksize,
'Content-Type': 'video/webm',
}
res.writeHead(206, head)
file.pipe(res)
} else {
const head = {
'Content-Length': fileSize,
'Content-Type': 'video/webm',
}
res.writeHead(200, head)
fs.createReadStream(path).pipe(res)
}
})
// Listen both http & https ports
const httpServer = http.createServer(app);
const httpsServer = https.createServer({
key: fs.readFileSync('server.key'),
cert: fs.readFileSync('server.cert'),
}, app);
httpServer.listen(8082, () => {
console.log(`HTTP Server running on http://localhost:${httpPort}`);
});
httpsServer.listen(443, () => {
console.log(`HTTPS Server running on http://localhost:${httpsPort}`);
});
// remember to delete above and uncommment below on deployment
// Listen both http & https ports
// const httpServer = http.createServer(app);
// const httpsServer = https.createServer({
// key: fs.readFileSync('/etc/letsencrypt/live/justcatalyst.com/privkey.pem'),
// cert: fs.readFileSync('/etc/letsencrypt/live/justcatalyst.com/fullchain.pem'),
// }, app);
//
// httpServer.listen(80, () => {
// console.log(`HTTP Server running on http://localhost:${httpPort}`);
// });
//
// httpsServer.listen(443, () => {
// console.log(`HTTPS Server running on http://localhost:${httpsPort}`);
// });