-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
27 lines (25 loc) · 895 Bytes
/
main.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
var fs = require("fs"),
http = require("http"),
request = require('request'),
url = require('url'),
exec = require("child_process").exec;
http.createServer(responseHandler).listen(process.env.PORT || 8888);
function responseHandler(req, res) {
var md5 = require('MD5');
res.writeHead(200, {"Content-Type": "text/html"});
if (req.url === "/") {
res.end();
} else if (req.url.match("/gravatar/")) {
var hash = "";
hash = md5(req.url.match(/gravatar\/(.*)/)[1]);
res.write("http://www.gravatar.com/avatar/" + hash);
} else if (req.url.match("/Calc/")) {
var evaluation = eval(req.url.match(/Calc\/(.*)/)[1]);
res.write(evaluation.toString());
} else if(req.url.match("Counts")){
var letters = (req.url.match(/Counts\/(.*)/)[1]).length;
var words = (req.url).split(" ").length;
res.write("Letters = "+ letters + "; words = " + words);
}
res.end();
}