-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
35 lines (29 loc) · 990 Bytes
/
server.js
File metadata and controls
35 lines (29 loc) · 990 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
32
33
34
35
'use strict';
var http = require("http");
(function run() {
if(require.main === module) {
start();
}
})();
function start() {
http.createServer(function (request, response) {
request.setEncoding('utf8');
request.addListener('data', function(postDataChunk) {
// Send response to the client after the first data chunk
request.removeAllListeners('data');
request.removeAllListeners('end');
response.writeHead(400, {'Content-Type': 'text/plain'});
response.end('First chunk received.', function(){
console.log(`server: "First chunk received." response sent to client`);
});
});
request.addListener('end', function() {
// This will never happen
response.writeHead(200, {'Content-Type': 'text/plain'});
return response.end('OK', function(){
console.log(`server: "OK" response sent to client.`);
});
});
}).listen(10345);
};
exports.start = start;