-
Notifications
You must be signed in to change notification settings - Fork 70
/
server.js
837 lines (753 loc) · 22.2 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
var express = require('express');
var MongoStore = require('connect-mongo')(express)
var settings = require('./settings');
var request = require('request');
var port = settings.port || 8888;
var sandboxOrigin = settings.sandboxOrigin || "http://sandbox.localhost:8888";
var shareSandboxOrigin = sandboxOrigin + "/s";
var embedSandboxOrigin = sandboxOrigin + "/e";
//SERVER SIDE TEMPLATES
GLOBAL.Handlebars = require('handlebars');
require('./templates/server-templates');
//SESSION SETUP
var ONE_YEAR = 1000 * 60 * 60 * 24 * 365;
var mongoConf = {
type: 'Mongo',
host: 'localhost',
port: 27017,
db: 'tributary'
}
//MONGO SETUP
var mongo = require('mongoskin');
var db = mongo.db('mongodb://' + mongoConf.host + ':' + mongoConf.port + '/' + mongoConf.db + '?auto_reconnect');
//collection to store some info on our users
var $users = db.collection("users");
//collection where we store info on inlets that are created and saved
var $inlets = db.collection("inlets");
//collection where we store visits (specifically to particular inlets)
var $visits = db.collection("visits");
//collection where we store images uploaded for thumbnails
var $images = db.collection("images");
//collection to store a cache of gists (for faster loading)
var cache = require('./cache');
var $gistcache = db.collection("gists");
$gistcache.ensureIndex({gistid:1}, false, function(err) { console.log(err) });
var app = express()
.use(express.compress())
.use(express.cookieParser())
.use(express.bodyParser())
.use(express.session({
secret: settings.SECRET,
cookie: {maxAge: ONE_YEAR},
store: new MongoStore(mongoConf)
}))
.use('/static', express.static(__dirname + '/static'))
app.use(express.vhost('sandbox.' + settings.hostname || "localhost", require(__dirname + '/sandbox').app))
app.get("/", index);
function index(req, res, next) {
res.sendfile(__dirname + '/templates/index.html');
};
app.get("/svgopen2012", svgopen);
function svgopen(req, res, next) {
res.sendfile(__dirname + '/templates/svgopen2012.html');
};
//API endpoint for fetching a gist from github
app.get("/gist/:gistid", getgist_endpoint);
function getgist_endpoint(req, res, next) {
getgist(req.params.gistid, function(error, response, body) {
if (!error && response.statusCode == 200) {
res.header("Content-Type", 'application/json');
res.send(body);
} else {
if(response) {
res.send({error: error, status: response.statusCode});
} else {
res.send(error)
}
}
})
}
function getgist(gistid, callback) {
var url = 'https://api.github.com/gists/' + gistid
+ "?client_id=" + settings.GITHUB_CLIENT_ID
+ "&client_secret=" + settings.GITHUB_CLIENT_SECRET;
request.get({
url: url
, headers: { 'User-Agent': 'tributary' }
}, callback);
}
//Base view in tributary.
app.get('/inlet', inlet)
app.get('/inlet/:gistid', inlet)
app.get('/tributary', inlet)
app.get('/tributary/:gistid', inlet)
//backwards compatible endpoints...
app.get('/tributary/:gistid/:filename', inlet)
app.get('/delta/:gistid', inlet)
app.get('/delta/:gistid/:filename', inlet)
app.get('/s/:gistid', inlet)
app.get('/e/:gistid', inlet)
function inlet(req,res,next) {
var gistid = req.params['gistid'];
// invalidate the cache if get provides ?update=true
if(req.query['update']) {
cache.invalidate($gistcache, gistid, function(err) { if(err) console.log(err)})
}
var user = req.session.user;
if(gistid) {
//record this visit
var visit = {
gistid: gistid
, createdAt: new Date()
}
if(user) {
visit.user = {
id: user.id
, login: user.login
}
}
$visits.save(visit, function(err, res) { if(err) console.log(err) });
}
try {
//serialize the query params so we can pass them to the inlet
var query = JSON.stringify(req.query);
} catch(e) {
var query = "";
}
var template = Handlebars.templates.header;
var context = {
user: user,
avatar_url: user? user.avatar_url : "",
loggedin: user ? true : false,
gistid: gistid,
query: query,
};
if(req.route.path === '/s/:gistid') {
context.shareRoute = true;
context.sandboxOrigin = shareSandboxOrigin
} else if(req.route.path === '/e/:gistid') {
context.embedRoute = true;
context.sandboxOrigin = embedSandboxOrigin
} else {
context.inletRoute = true;
context.sandboxOrigin = sandboxOrigin
}
var html = template(context);
res.send(html);
}
//Save an inlet
app.post('/tributary/save', save_endpoint)
app.post('/tributary/save/:gistid', save_endpoint)
function save_endpoint(req,res,next) {
var data = req.body.gist;
var token = req.session.access_token;
var gistid = req.params['gistid'];
console.log("SAVING", gistid);
save(gistid, data, token, function(err, response) {
if(!err) {
//post save
after_save(response, function(error, newgist) {
if(!error && newgist) {
return res.send(newgist);
}
res.send(error);
})
//return updated gist
} else {
res.send(err);
}
})
}
//Fork an inlet
app.post('/tributary/fork', fork_endpoint)
app.post('/tributary/fork/:gistid', fork_endpoint)
function fork_endpoint(req,res,next) {
var data = req.body.gist;
var token = req.session.access_token;
var user = req.session.user;
var gistid = req.params['gistid'];
console.log("FORKING", gistid);
//get the user of this gist
if(!gistid || !user) {
//No id, so creating a new gist
//or anon user, can't make anon fork so create new gist
console.log("creating new gist");
newgist(data, token, function (err, response) {
if(!err) {
if(!user) return res.send(response);
console.log("after fork");
after_fork(undefined, response, token, function(error, newgist) {
if(!error) {
return res.send(newgist);
}
res.send(error);
})
} else {
res.send(err);
}
})
} else {
getgist(gistid, function(err, response, body) {
if(!err && response.statusCode === 200) {
var oldgist = JSON.parse(body);
if( !oldgist.user || oldgist.user.id !== user.id) {
console.log("forking gist");
//we don't use github's fork because it doesn't accept changes made
//by another user
//fork(gistid, data, token, onResponse);
newgist(data, token, onResponse);
} else {
//logged in user can't fork themselves
//so create a new gist
console.log("forking self");
newgist(data, token, onResponse);
}
function onResponse(err, response) {
if(!err) {
//post fork. but only if user is authenticated
after_fork(oldgist, response, token, function(error, newgist) {
if(!error) {
return res.send(newgist);
}
res.send(error);
})
}
}
} else {
res.send(response.statusCode);
}
})
}
}
function newgist(data, token, callback) {
//USER saves new gist
var url = 'https://api.github.com/gists'
var method = "POST";
var headers = {
'User-Agent': 'tributary'
, 'content-type': 'application/json'
, 'accept': 'application/json'
};
if(token) {
headers['Authorization'] = 'token ' + token;
}
request({
url: url,
body: data.toString(),
method: method,
headers: headers
}, onResponse)
function onResponse(error, response, body) {
if (!error && response.statusCode == 201) {
callback(null, JSON.parse(body));
} else {
callback(error, null);
}
}
}
function save(gistid, data, token, callback) {
//USER saves over existing gist
var url = 'https://api.github.com/gists/' + gistid
var method = "PATCH";
var headers = {
'User-Agent': 'tributary'
, 'content-type': 'application/json'
, 'accept': 'application/json'
, 'Authorization': 'token ' + token
};
var string = data.toString();
request(url,{
body: string,
method: method,
headers: headers
}, onResponse)
function onResponse(error, response, body) {
if (!error && response.statusCode == 200) {
callback(null, JSON.parse(body));
} else {
callback(error, response.statusCode);
}
}
}
//Fork an inlet
function fork(gistid, data, token, callback) {
//NOTE: this will only work when an authenticated user
//forks a gist that is not his or hers
var url = 'https://api.github.com/gists/' + gistid + '/forks'
var method = "POST";
var headers = {
'User-Agent': 'tributary'
, 'Authorization': 'token ' + token
}
request({
url: url,
method: method,
body: "{}",
headers: headers
}, onResponse)
function onResponse(error, response, body) {
if (!error && response.statusCode == 201) {
callback(null, JSON.parse(body));
} else {
callback(error, null);
}
}
}
//post save functionality
function after_fork(oldgist, newgist, token, callback) {
//update history in _.md and provide live urls
//check for existing _.md in oldgist
var gist_hist = "";
try {
gist_hist = oldgist.files["_.md"].content;
} catch (e) {
} finally {
}
if(!newgist) return callback({status:500}, null)
var user = newgist.owner || newgist.user;
var name = "anon";
if(user) name = user.login;
var markdown = "[ <a href=\"http://tributary.io/inlet/" + newgist.id +"\">Launch: " + newgist.description + "</a> ] "
+ newgist.id
+ " by " + name
+ "<br>"
markdown += gist_hist;
newgist.files['_.md'] = {
"content": markdown
}
//update/set raw url for thumbnail in config
var inlet_data = {
gistid: newgist.id
, createdAt: new Date()
, description: newgist.description
, public: newgist['public']
}
if(user) {
inlet_data.user = {
id: user.id
, login: user.login
}
}
//update mongo
if(oldgist) {
//this is a fork, update the old gist
inlet_data.parent = oldgist.id;
}
try {
var config = JSON.parse(gist.files['config.json'].content);
var thumbnail = config.thumbnail;
if(thumbnail) {
inlet_data.thumbnail = thumbnail;
}
} catch (e) {}
$inlets.save(inlet_data, function(err, result) { if(err) console.error(err); });
save(newgist.id, JSON.stringify(newgist), token, callback);
}
//post save functionality
function after_save(gist, callback) {
// after a save, invalidate our cached gist
cache.invalidate($gistcache, gist.id, function(err) { if(err) console.log(err) })
//update the raw url for the thumbnail
//save info in mongo.
//if gist doesn't exist in mongo, we create it, otherwise we update it.
$inlets.findOne({gistid: gist.id}, function(err, mgist) {
if(!mgist) {
mgist = {
gistid: gist.id
, createdAt: new Date()
, description: gist.description
, public: newgist['public']
}
}
var user = gist.owner || gist.user
if(user) {
mgist.user = {
id: user.id
, login: user.login
}
}
mgist.description = gist.description
mgist.lastSave = new Date();
try {
var config = JSON.parse(gist.files['config.json'].content);
var thumbnail = config.thumbnail;
mgist.thumbnail = thumbnail;
} catch (e) {}
$inlets.update({ gistid: gist.id}, mgist, {upsert:true}, function(err, result) { if(err) console.error(err); });
})
callback(null, gist);
}
/*
* Authentication
*/
app.get("/github-authenticated", github_authenticated)
function github_authenticated(req,res,next) {
var tempcode = req.query.code || '';
var data = {
'client_id': settings.GITHUB_CLIENT_ID,
'client_secret': settings.GITHUB_CLIENT_SECRET,
'code': tempcode
}
var headers = {
'User-Agent': 'tributary'
//, 'content-type': 'application/json'
, 'accept': 'application/json'
}
//well, github just decided that it didn't want json payload anymore...
var url = 'https://github.com/login/oauth/access_token';
url += "?client_id=" + data.client_id;
url += "&client_secret=" + data.client_secret;
url += "&code=" + data.code;
// request an access token
request({
url: url,
method: "POST",
headers: headers
}, function(error, response, body) {
if (!error && response.statusCode == 200) {
var access_token;
try {
access_token = JSON.parse(body).access_token;
req.session.access_token = access_token;
} catch (e) {
return res.redirect('/404')
}
request({
url: "https://api.github.com/user?access_token=" + access_token
, headers: headers
}, function(e,r,b){
if (!e && r.statusCode == 200) {
//store info about the user in the session
req.session.user = JSON.parse(b);
var user = req.session.user;
$users.update({ id: user.id}
, user
, { upsert: true }, function(err, result) { if(err) console.error(err); });
//redirect to where the user was
if(req.query.state && req.query.state !== "/undefined"){
res.redirect(req.query.state)
} else {
res.redirect('/inlet');
}
}
})
} else {
console.log("authentication error!", error);
res.redirect('/404')
}
})
}
app.get('/github-login', github_login)
app.get('/github-login/:product', github_login)
app.get('/github-login/:product/:id', github_login)
function github_login(req,res,next) {
var product, id;
var url = "https://github.com/login/oauth/authorize?client_id="
+ settings.GITHUB_CLIENT_ID
+ "&scope=gist";
if(req.params['product']) {
product = '/' + req.params['product'];
} else {
product = "/inlet";
}
if(req.params['id']) {
id = '/' + req.params['id']
} else {
id = '';
}
url += "&state=" + product + id;
res.redirect(url);
}
app.get('/github-logout', github_logout)
app.get('/github-logout/:product', github_logout)
app.get('/github-logout/:product/:id', github_logout)
function github_logout(req,res,next) {
req.session.access_token = null;
req.session.user = null;
if(req.params['product']) {
product = '/' + req.params['product'];
} else {
product = "/inlet";
}
if(req.params['id']) {
id = '/' + req.params['id']
} else {
id = '';
}
res.redirect(product + id);
}
//IMGUR
app.get("/imgur-authenticated", imgur_authenticated)
function imgur_authenticated(req,res,next) {
//TODO: set this up
console.log("imgur authenticated");
next();
}
app.post("/imgur/upload/thumbnail", imgur_upload)
function imgur_upload(req,res,next) {
var data = req.body.image;
var user = req.session.user;
if(!user) { return res.send({status: 401}); }
var url = 'https://api.imgur.com/3/image'
var method = "POST";
var headers = {
'User-Agent': 'tributary'
, 'Authorization': 'Client-ID ' + settings.IMGUR_CLIENT_ID
};
request({
url: url,
json: {"image": data},
method: method,
headers: headers
}, onResponse)
function onResponse(error, response, body) {
if (!error && response.statusCode == 200) {
//save in mongo
var image_data = {
link: body.data.link
, deletehash: body.data.deletehash
, user: {
id: user.id
, login: user.login
}
}
$images.save(image_data, function(err, result) { if(err) console.error(err); });
} else {
}
res.send(body)
}
}
//API
function find_inlet(gistid, callback){
var query = {
"gistid": gistid
, public: { $ne: false }
};
$inlets.findOne(query, callback);
}
app.get('/api/inlet/:gistid', get_inlet_family)
function get_inlet_family(req, res, next){
res.header("Access-Control-Allow-Origin", "*");
find_inlet(req.params.gistid, function(err, foundInlet) {
if (err) res.send(err);
// Fill in the parent of foundInlet the first time through
getParent(foundInlet, foundInlet, res);
});
}
function getParent(foundInlet, inlet, res){
// 'foundInlet' is only used with res.send()
// 'inlet' is the current inlet having its parent filled in.
// The first time the function is called the two are the same.
if(!inlet) return res.send(404);
if (inlet.parent){
find_inlet(inlet.parent, function(err, foundParentInlet){
if (err) res.send(err);
inlet.parent = foundParentInlet;
// Recurse and fill in the parent of 'inlet'
// Pass the original 'foundInlet' along too.
getParent(foundInlet, inlet.parent, res)
});
}
else {
// When the recursion is complete, return the original 'foundInlet'
res.send(foundInlet);
}
}
app.get('/api/latest/created', latest_created)
app.get('/api/latest/created/:limit', latest_created)
function latest_created(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
var query = {
public: { $ne: false }
};
//TODO: pagination
var limit = req.params.limit || 400;
var end = req.params.end || new Date();
$inlets.find(query, {limit: limit}).sort({ createdAt: -1 }).toArray(function(err, inlets) {
if(err) res.send(err);
res.send(inlets);
})
}
app.get('/api/latest/forks', latest_forks)
app.get('/api/latest/forks/:limit', latest_forks)
function latest_forks(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
var query = {
public: { $ne: false }
, parent: {$exists: true}
};
//TODO: pagination
var limit = req.params.limit || 400;
$inlets.find(query, {limit: limit}).sort({ createdAt: -1 }).toArray(function(err, inlets) {
if(err) res.send(err);
res.send(inlets);
})
}
app.get('/api/latest/visits', latest_visits)
app.get('/api/latest/visits/:start/:end', latest_visits)
function latest_visits(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
var start = req.params.start || new Date(new Date() - (24 * 60 * 60 * 1000));
var end = req.params.end || new Date();
var query = dateQuery(start, end);
query['public'] = {$ne: false};
//TODO: pagination
var limit = 2000;
$visits.find(query, {limit: limit}).sort({ createdAt: -1 }).toArray(function(err, inlets) {
if(err) res.send(err);
res.send(inlets);
})
}
app.get('/api/users', api_users)
app.get('/api/users/:sortby/:limit/:ascdsc', api_users)
function api_users(req,res,next) {
res.header("Access-Control-Allow-Origin", "*");
var sortBy = req.params.sortby || "createdAt";
var ascdsc = parseInt(req.params.ascdsc) || 1;
var limit = req.params.limit || 200;
var query = {
public: { $ne: false }
};
//TODO: pagination
var fields = {
name: 1,
login: 1,
id: 1,
avatar_url: 1,
html_url: 1,
inlets: 1,
visits: 1,
nforks: 1
}
var opts = {
limit: limit
}
var sort = {}
sort[sortBy] = ascdsc
//TODO: make sure this is secure in the future
$users.find(query, fields, opts).sort(sort).toArray(function(err, users) {
if(err) res.send(err);
res.send(users);
})
}
app.get('/api/user/:login/latest', user_latest)
app.get('/api/user/:login/latest/:limit', user_latest)
app.get('/api/user/:login/latest/:limit/:skip', user_latest)
function user_latest(req,res,next) {
res.header("Access-Control-Allow-Origin", "*");
var skip = req.params.skip || 0
var query = {
"user.login": req.params.login
, public: { $ne: false }
};
//TODO: pagination
var limit = req.params.limit || 200;
$inlets.find(query, {limit: limit, skip: skip}).sort({ createdAt: -1 }).toArray(function(err, inlets) {
if(err) res.send(err);
res.send(inlets);
})
}
//Reporting API
app.get('/api/counts/inlets', counts_inlets)
app.get('/api/counts/inlets/:start/:end', counts_inlets)
function counts_inlets(req,res,next) {
res.header("Access-Control-Allow-Origin", "*");
var start = req.params.start || new Date(new Date() - (24 * 60 * 60 * 1000));
var end = req.params.end || new Date();
var query = dateQuery(start, end);
query['public'] = {$ne: false};
//TODO: pagination
var limit = 200;
$inlets.count(query, {limit: limit}, function(err, ninlets) {
if(err) res.send(err);
res.send({
start: start,
end: end,
count:ninlets
});
});
}
app.get('/api/counts/visits', counts_visits)
app.get('/api/counts/visits/:start/:end', counts_visits)
function counts_visits(req,res,next) {
res.header("Access-Control-Allow-Origin", "*");
var start = req.params.start || new Date(new Date() - (24 * 60 * 60 * 1000));
var end = req.params.end || new Date();
var query = dateQuery(start, end);
query['public'] = {$ne: false};
//TODO: pagination
var limit = 200;
$visits.count(query, {limit: limit}, function(err, nvisits) {
if(err) res.send(err);
res.send({
start: start,
end: end,
count:nvisits
});
});
}
app.get('/api/most/viewed', most_viewed)
function most_viewed(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
var query = {
public: {$ne: false}
};
//TODO: pagination
var limit = 200;
$inlets.find(query, {limit: limit}).sort({ "visits": -1 }).toArray(function(err, inlets) {
if(err) res.send(err);
res.send(inlets);
})
}
app.get('/api/most/forked', most_forked)
function most_forked(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
var query = {
public: {$ne: false}
};
//TODO: pagination
var limit = 200;
$inlets.find(query, {limit: limit}).sort({ "nforks": -1 }).toArray(function(err, inlets) {
if(err) res.send(err);
res.send(inlets);
})
}
app.get('/api',api_endpoints)
var api_routes;
function api_endpoints(req, res, next) {
res.header("Access-Control-Allow-Origin","*");
if (!api_routes) {
api_routes = {};
for (rtype in app.routes) { // get, post, put, delete
api_routes[rtype] = [];
for (r in app.routes[rtype]) {
if (app.routes[rtype][r].path.substring(0,4) === "/api") {
api_routes[rtype].push(app.routes[rtype][r])
}
}
}
}
res.send(api_routes);
}
function dateQuery(start, end) {
var query = {
$and: [ { createdAt: { $gt: new Date(start)}}, { createdAt:{ $lte: new Date(end)}}],
}
return query;
}
/*
app.get("/api/proxy", proxy)
function proxy(req, res, next) {
var url = req.query.url;
if(!url ){ return res.send(404) }
request.get({
url: url
, headers: { 'User-Agent': 'tributary' }
}, function(err, response, body) {
res.send(body);
})
}
*/
app.listen(port, function() {
console.log("tributary running on port", port);
});