-
Notifications
You must be signed in to change notification settings - Fork 4
/
component_combiner.js
57 lines (50 loc) · 1.34 KB
/
component_combiner.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
var http = require('http');
var port = process.env.PORT || 8000;
var fs = require('fs');
var components = [
'/components/typography.html',
'/components/colors.html',
'/components/form.html',
'/components/button.html',
'/components/image.html',
'/components/grid.html',
'/components/code.html',
'/components/table.html',
'/components/navbar.html',
'/components/customisation.html'
];
var server = http.createServer(function (req, res) {
if (req.url === '/') {
homeHandler(req, res);
} else if (components.indexOf(req.url) > -1) {
componentHandler(req, res);
} else if (req.url === '/style.css') {
cssHandler(req, res);
}
}).listen(port);
function homeHandler (req, res) {
res.writeHead(200, {'Content-type': 'text/html'});
fs.readFile('index.html', function (err, data) {
if (err) throw err;
res.end(data);
});
}
function componentHandler (req, res) {
var file = req.url.replace('/', '');
res.writeHead(200, {'Content-type': 'text/html'});
fs.readFile(file, function (err, data) {
if (err) throw err;
res.end(data);
});
}
function cssHandler (req, res) {
res.writeHead(200, {'Content-type': 'text/css'});
fs.readFile('style.css', function (err, data) {
if (err) throw err;
res.end(data);
});
}
console.log("Go to http://localhost:" + port);
module.exports = {
init: server
};