forked from TilakPutta-zz/simpleHTTP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
29 lines (25 loc) · 832 Bytes
/
app.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
const net = require('net');
const Request = require('./handlers/request');
const Response = require('./handlers/response');
const resolveAPI = require('./helpers/Resolver').resolveAPI;
global.jobs = {};
net.createServer(function (socket) {
socket.on('data', function (data) {
req = new Request(data);
res = new Response(socket);
try{
responseObj = resolveAPI(req, res) || {};
} catch(err) {
res.sendError({
status: -1,
message: 'Something went wrong!'
}, 500);
console.log('Internal Error!', 500);
}
socket.destroy();
});
}).listen(process.env.PORT || 3104, () => {
process.stdout.write('Server listening at http://localhost:'+(process.env.PORT || 3104)+'\n');
}).on('error', (err) => {
console.log('Server error: '+err.toString())
});