This repository has been archived by the owner on May 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.js
80 lines (62 loc) · 2.29 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
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
'use strict';
module.exports = function (config) {
global.Promise = require('es6-promise').Promise;
var
bodyParser = require('body-parser'),
express = require('express'),
expressUtils = require('express-utils'),
handlerMiddleware = require('./lib/handler-middleware'),
patchHeadersMiddleware = require('./lib/patch-headers-middleware'),
morgan = require('morgan'),
path = require('path'),
bunyan = require('bunyan'),
renderHtmlMiddleware = require('./lib/render-html-middleware'),
sparqlProxy = require('./lib/sparql-proxy'),
sparqlSearch = require('./lib/sparql-search');
global.log = bunyan.createLogger({
name: config.app,
level: config.logger.level
});
if (!('init' in config)) {
config.init = function () {
return Promise.resolve();
};
}
return config.init()
.then(function () {
var
app = express(),
handler = new config.HandlerClass(config.handlerOptions);
if ('expressSettings' in config) {
for (var key in config.expressSettings) {
app.set(key, config.expressSettings[key]);
}
}
app.use(morgan('combined'));
app.use(patchHeadersMiddleware(config.patchHeaders));
app.use(bodyParser.text());
app.use(bodyParser.urlencoded({extended: false}));
// instance files
if (__dirname !== process.cwd()) {
app.use(express.static(path.join(process.cwd(), './data/public/')));
}
// trifid files
app.use(express.static(path.join(__dirname, './data/public/')));
// yasgui files
app.use('/sparql/dist/', express.static(path.resolve(require.resolve('yasgui'), '../../dist/')))
app.use(expressUtils.absoluteUrl());
if ('sparqlProxy' in config) {
app.use(config.sparqlProxy.path, sparqlProxy(config.sparqlProxy.options));
}
if ('sparqlSearch' in config) {
app.use(config.sparqlSearch.path, sparqlSearch(config.sparqlSearch.options));
}
app.use(renderHtmlMiddleware(handler));
app.use(handlerMiddleware(handler));
app.listen(config.listener.port, config.listener.hostname);
log.info('listening on hostname:port: ' + config.listener.hostname + ':' + config.listener.port);
})
.catch(function (error) {
console.error(error.stack);
});
}