forked from tobie/specref
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (46 loc) · 1.28 KB
/
index.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
var t0 = Date.now();
var express = require("express"),
cors = require("connect-cors"),
bibref = require('./lib/bibref');
XREFS = require('./xrefs');
var app = module.exports = express();
// Configuration
app.configure(function(){
app.use(cors());
app.use(express.bodyParser());
app.use(app.router);
});
app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('production', function(){
app.use(express.errorHandler());
});
// bibrefs
app.get('/bibrefs', function (req, res, next) {
var refs = req.param("refs");
if (refs) {
refs = bibref.getRefs(refs.split(","));
res.jsonp(refs);
} else {
res.jsonp(bibref.all);
}
});
// xrefs
app.get('/xrefs', function (req, res, next) {
var data = {};
var refs = req.param("refs");
if (refs) {
refs.split(",").forEach(function(ref) {
if (XREFS[ref]) data[ref] = XREFS[ref];
});
res.jsonp(data);
} else {
res.jsonp(XREFS);
}
});
var port = process.env.PORT || 5000;
app.listen(port, function () {
console.log("Express server listening on port %d in %s mode", port, app.settings.env);
console.log("App started in", (Date.now() - t0) + "ms.");
});