-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
31 lines (28 loc) · 926 Bytes
/
server.js
File metadata and controls
31 lines (28 loc) · 926 Bytes
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
var url = require('url');
var fs = require('fs');
var router = {
"/chart.js": "/node_modules/chart.js/dist/Chart.js",
"/bootstrap.min.css": "/node_modules/bootstrap/dist/css/bootstrap.min.css",
"/bootstrap-theme.min.css": "/node_modules/bootstrap/dist/css/bootstrap-theme.min.css"
};
module.exports = function handler (req, res){
var servefile = function (err, data) {
if (err) {
console.log(err);
res.writeHead(500);
return res.end('Error loading');
}
res.writeHead(200);
res.end(data);
};
var path = url.parse(req.url).pathname;
if (path === '/dashboard.js' || path === '/index.html' || path === "/"){
path = (path === '/dashboard.js') ? '/dashboard.js' : "/index.html";
fs.readFile(__dirname + path, servefile);
}else if (router[path] !== undefined) {
fs.readFile(__dirname + router[path], servefile);
}else{
res.writeHead(404);
res.end();
}
};