-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
49 lines (34 loc) · 1.07 KB
/
server.js
File metadata and controls
49 lines (34 loc) · 1.07 KB
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
// Linking to other files
tracker = require('./tracker.js');
db = require('./dbManager.js');
trend = require('./trendManager.js');
express = require('express');
var port = 31010;
// Making a function be executed every hour:
var interval = 3600000; // 1 hour in milliseconds
// Create an express application
var app = express();
// Configuring the app
app.configure(function (req, res) {
app.use(express.bodyParser());
});
/// Define the REST API:
// Define POST:
app.post('/blog', tracker.postBlog);
// Define GET:
app.get('/blog/:hostname/trends/:order/:limit', trend.trendBlog);
app.get('/blog/:hostname/trends/:order', trend.trendBlog);
app.get('/blogs/trends/:order/:limit', trend.trendAll);
app.get('/blogs/trends/:order', trend.trendAll);
app.listen(port);
var runningFunction = setInterval(everyhourFunction, interval);
db.createDB(function(){
// Lauch the tracker as soon as the server begin
everyhourFunction();
});
function everyhourFunction() {
// Code to be executed:
db.updateAll();
}
// [If necessary] Removing the running condition:
//clearInterval(interval);