-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
109 lines (86 loc) · 2.71 KB
/
app.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
/**
* Module dependencies.
*/
var express = require('express');
var routes = require('./routes');
var resolver = require('./routes/resolver');
var http = require('http');
var path = require('path');
var request = require('request');
var app = express();
// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
//app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
var repository;
var yaml = require('js-yaml');
var fs = require('fs');
var context_map = {}
var source_map = {
"obo_context": "https://raw.githubusercontent.com/cmungall/biocontext/master/registry/obo_context.jsonld",
"semweb_vocab_context": "https://raw.githubusercontent.com/cmungall/biocontext/master/registry/semweb_vocab_context.jsonld",
"semweb_context": "https://raw.githubusercontent.com/cmungall/biocontext/master/registry/semweb_context.jsonld"
};
var load_context = function(name, url) {
console.log("Loading:"+name+" "+url);
request({
url: url,
json: true
}, function (error, response, body) {
if (!error && response.statusCode === 200) {
context_map[name] = body['@context']
}
})
};
for (var n in source_map) {
load_context(n, source_map[n]);
}
// Make our repository accessible to our router
app.use(function(req,res,next){
req.context_map = context_map;
next();
});
app.get('/', resolver.list);
app.get('/resolve/:name', resolver.resolve);
app.get('/resolve', resolver.resolve);
app.get('/info/:name', resolver.resolve);
app.get('/info', resolver.resolve);
//app.get('/ontologies', ontology.list);
//app.get('/ontology/:id', ontology.info);
//app.get('/obo/*', ontology.fall_through);
app.get('/about',
function(req, res){ res.render('about')});
/// error handlers
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
console.error("ERRPR");
console.error(err.stack);
//res.render('error', {
// message: err.message,
// error: err
//});
res.send(500);
});
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
//res.render('error', {
// message: err.message,
// error: {}
//});
});
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});