-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
67 lines (51 loc) · 1.17 KB
/
server.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
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
var connect = require('connect');
var url = require('url');
var app = connect();
var result = function(req, res, next) {
var qs = url.parse(req.url, true).query;
var method = qs.method;
var x = qs.x;
var y = qs.y;
if (method === 'add') {
var total = parseFloat(x) + parseFloat(y);
res.writeHead(200, {
"Content-Type": "text-plain"
});
res.write(x + " + " + y + " = " + total);
res.end();
}
if (method === 'subtract') {
var total = parseFloat(x) - parseFloat(y);
res.writeHead(200, {
"Content-Type": "text-plain"
});
res.write(x + " - " + y + " = " + total);
res.end();
}
if (method === 'multiply') {
var total = parseFloat(x) * parseFloat(y);
res.writeHead(200, {
"Content-Type": "text-plain"
});
res.write(x + " * " + y + " = " + total);
res.end();
}
if (method === 'divide') {
var total = parseFloat(x) / parseFloat(y);
res.writeHead(200, {
"Content-Type": "text-plain"
});
res.write(x + " / " + y + " = " + total);
res.end();
}
else {
res.writeHead(200, {
"Content-Type": "text-plain"
});
res.write("Invalid QueryString.");
res.end();
}
}
app.use('/lab3', result);
app.listen(3000);
console.log ('connect app running http://localhost:300/');