-
Notifications
You must be signed in to change notification settings - Fork 1
/
feedserver.js
65 lines (50 loc) · 1.93 KB
/
feedserver.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
var http = require("http");
var sys = require("sys");
var url = require('url');
var path = require('path');
var querystring = require('querystring');
require('./lib/dep/date');
var direttoUtil = require("./lib/diretto/util");
var cradle = require('./lib/dep/cradle');
var Auth = require('./lib/diretto/auth').Auth;
var Signer = require('./lib/diretto/signer').Signer;
var SimpleRouter = require('./lib/diretto/simplerouter').SimpleRouter;
var FeedHandler = require('./lib/diretto/feedhandler').FeedHandler;
var SERVER = {
name : "DirettoFeedNode",
version : "0.1.0",
alias : "DirettoFeedNode/0.1.0"
};
var config = direttoUtil.readConfigFile("./conf/servers.json");
var cachingConnection = new (cradle.Connection)(config.couchdb.host, config.couchdb.port, {
cache : true,
raw : false
});
var feedHandler = new FeedHandler(config, SERVER);
var pushing = (process.argv.indexOf("--nopush") === -1);
var urls = [ [ 'GET', '^\/feeds\/documents(?:\/cursor\/([a-zA-Z0-9-]+))?$', function(request, response, cursor) {
feedHandler.getDocumentPage(request, response, cursor);
} ], [ 'GET', '^\/geo\/kml(?:\/cursor\/([a-zA-Z0-9-]+))?$', function(request, response, cursor) {
feedHandler.getKmlFeed(request, response);
} ], [ 'GET', '^\/feeds\/attachments(?:\/cursor\/([a-zA-Z0-9-]+))?$', function(request, response, cursor) {
feedHandler.getAttachmentPage(request, response, cursor);
} ], [ 'POST', '^/bla/(.+)$', function(request, response, bla, q) {
response.writeHead(200, {
'Content-Type' : 'text/plain'
});
if (q.foo) {
response.write(q.foo);
}
response.end(bla + 'World\n');
} ], [ 'GET', '^\/([a-zA-Z0-9-]+)?$', function(request, response, bla) {
response.writeHead(200, {});
response.end(bla);
} ] ];
var router = new SimpleRouter(urls, SERVER);
router.listen(config.feedserver.port, config.feedserver.ip);
if (pushing) {
feedHandler.startChangeHandler();
}
process.on('uncaughtException', function (err) {
sys.log('Caught exception: ' + err);
});