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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
/*
* pnhandler.js
*
* group of methods that handles different pathnames
*/
var util = require('util');
var querystring = require('querystring');
function noop(query, reqdata, res) {
util.log('[pnhandler] handling ' + query.pathname +
', ok who the fuck is messing with us?');
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end();
}
function register(query, reqdata, res) {
util.log('[pnhandler] handling ' + query.pathname);
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end();
}
function login(query, reqdata, res) {
util.log('[pnhandler] handling ' + query.pathname);
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end();
}
function poll(query, reqdata, res) {
util.log('[pnhandler] handling ' + query.pathname);
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end();
}
function upload(query, reqdata, res) {
util.log('[pnhandler] handling ' + query.pathname);
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end();
}
function info(query, reqdata, res) {
util.log('[pnhandler] handling ' + query.pathname);
var body =
'<!DOCTYPE html>\n' +
'<html>\n' +
'<head>\n' +
'<title>Info</title>\n' +
'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />\n' +
'</head>\n' +
'<body>\n' +
'<h1 style="background-color: gray; color: lime">Node.JS Server Info</h1>' +
'Node ' + process.version + ', uptime ' + process.uptime() + ' seconds' + '<br />' +
'Memory usage: ' + process.memoryUsage().heapTotal / (1024*1204) + 'MB<br />' +
'</body>\n' +
'</html>\n';
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(body);
res.end();
}
function hello(query, reqdata, res) {
util.log('[pnhandler] handling ' + query.pathname);
var body =
'<!DOCTYPE html>\n' +
'<html>\n' +
'<head>\n' +
'<title>Hello</title>\n' +
'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />\n' +
'</head>\n' +
'<body>\n' +
'<form action="/hellores" method="post">\n' +
'<textarea name="text" rows="20" cols="60"></textarea><br />\n' +
'<input type="submit" value="Submit text" />\n' +
'</form>\n' +
'</body>\n' +
'</html>\n';
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(body);
res.end();
}
function hellores(query, reqdata, res) {
util.log('[pnhandler] handling ' + query.pathname);
util.log('[pnhandler] hello recv:\n' + querystring.parse(reqdata).text);
var body =
'<!DOCTYPE html>\n' +
'<html>\n' +
'<head>\n' +
'<title>Hello Response</title>\n' +
'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />\n' +
'</head>\n' +
'<body>\n' +
'<p>You requested/sent:<br /></p>' +
querystring.parse(reqdata).text +
'</body>\n' +
'</html>\n';
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(body);
res.end();
}
exports.noop = noop;
exports.register = register;
exports.login = login;
exports.poll = poll;
exports.upload = upload;
exports.info = info,
exports.hello = hello;
exports.hellores = hellores;
|