-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathserver.js
More file actions
32 lines (26 loc) · 696 Bytes
/
Copy pathserver.js
File metadata and controls
32 lines (26 loc) · 696 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 http = require('http'),
fs = require('fs')
mime = require('mime');
var server = http.createServer(function(req, res) {
// send all urls to render index
var path = 'index.html';
// make exception for static assets
if (req.url.match(/^\/media/)) {
path = req.url;
}
var absPath = __dirname + '/' + path;
var mimeType = mime.lookup(absPath);
// load file
fs.readFile(absPath, function(error, content) {
if (error) {
res.writeHead(500);
res.end();
} else {
res.setHeader('Content-Type', mimeType);
res.writeHead(200);
res.end(content, 'utf-8');
}
});
});
server.listen(8000);
console.log('Listening on port: 8000');