-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
53 lines (53 loc) · 1.24 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
var Db = require('db');
exports.onInstall = function() {
return Db.shared.set('counter', 0);
};
exports.client_incr = function() {
log('hello world!');
return Db.shared.modify('counter', function(v) {
return v + 1;
});
};
exports.client_getTime = function(cb) {
return cb.reply(new Date());
};
exports.onHttp = function(request) {
Db.shared.set('http', request.data);
return request.respond(200, "Thanks for your input\n");
};
exports.client_fetchHn = function() {
var Http;
Http = require('http');
return Http.get({
url: 'https://news.ycombinator.com',
name: 'hnResponse'
});
};
exports.hnResponse = function(data) {
var all, id, m, re, title, url;
re = /<a href="(http[^"]+)">([^<]+)<\/a>/g;
id = 1;
while (id < 5 && (m = re.exec(data))) {
all = m[0], url = m[1], title = m[2];
log('hn headline', title, url);
if (url === 'http://www.ycombinator.com') {
continue;
}
Db.shared.set('hn', id, {
title: title,
url: url
});
id++;
}
};
exports.onPhoto = function(info) {
log('onPhoto', JSON.stringify(info));
Db.shared.set('photo', info.key);
};
return exports.client_event = function() {
var Event;
Event = require('event');
Event.create({
text: "Test event"
});
};