-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpreviewer.js
57 lines (41 loc) · 1.23 KB
/
previewer.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
//http server
const http = require('http');
//used to parse the request URL
const url = require('url');
//express app
const express = require("express");
//express app
const app = express();
//used to append static content to result
const includes = require('./includes/includes.js');
//used to append static content to result
const contentLoader = require('./includes/staticContentServer.js');
//port for the server to run on
const port = 8000;
/**
* Parses the request url and calls correct JS files
*/
app.use(function(request, result)
{
const filename = url.parse(request.url, true).pathname;
if(contentLoader.serveStaticContent(request, result, filename, ""))
{
//do nothing
}
else
{
result.writeHead(200, {'Content-Type': 'text/html'});
Promise.all([includes.printHeader(),
require('./blog/renderBlogPost.js').generateBlogPostComponent('/programming/', 'cs-theory-exam-2-review', -1),
includes.printFooter()]).then(function (content)
{
result.write(content.join(''));
result.end();
}).catch(function (err)
{
console.log(err);
throw err;
});
}
});
http.createServer(app).listen(port);