-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (33 loc) · 912 Bytes
/
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
const port = process.env.PORT;
// const port = '8080';
const host = '0.0.0.0';
var ASQ = require('asynquence');
var _ = require('lodash');
var url = require('url');
var http = require('http');
var server = http.createServer(handleRequest);
var fs = require('fs');
server.listen(port, host, function () {
console.log('Server listening on port: %s', port);
});
function handleRequest(req, res) {
fs.readFile('index.html', function (error, content) {
if (error) {
if (error.code == 'ENOENT') {
fs.readFile('./404.html', function (error, content) {
res.writeHead(200, { 'Content-Type': 'text\html' });
res.end(content, 'utf-8');
});
}
else {
res.writeHead(500);
res.end('Sorry, check with the site admin for error: ' + error.code + ' ..\n');
res.end();
}
}
else {
res.writeHead(200, { 'Content-Type': 'text\html' });
res.end(content, 'utf-8');
}
});
}