-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
81 lines (74 loc) · 1.46 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* User: conglei
* Date: 09/01/14
* Time: 13:51
*/
var host = "127.0.0.1";
var port = 8080;
var express = require("express");
var util = require("util");
var app = express();
//
//
var t = 1;
//
////fill in here
//
//
app.use(express.bodyParser()); // parse the data
//
//
app.get("/getdata",function(req,res){
var query = req.query;
var num = query['num'];
var output = [];
for (var i = 0; i < num; i++){
output.push(
{
time : t++,
value : Math.random() * 100
}
);
}
res.send(output);
res.end();
});
//app.get('/getdata', function(req,res){
// var query = req.query;
//// console.log(query);
// var num = query['num'];
// var output = [];
// for (var i = 0; i < num; i++){
// output.push(
// {
// time : t++,
// value : Math.random() * 100
// }
// );
// }
// res.send(output);
// res.end();
//});
//
app.get("/fake.txt", function(req,res){
var output = "this is a fake file!";
res.send(output);
res.end();
});
//
app.post("/reset", function(req,res){
var time = req.body.time;
t = time;
res.end();
})
//app.post("/reset", function(req,res){
// var time = req.body.time;
// t = time;
// res.end()
//});
//
//
//
app.use(express.static(__dirname)); //use static files in ROOT/public folder
app.listen(port, host);
console.log("Server Started: port: 8080.....");