-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
127 lines (109 loc) · 3.62 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*jslint vars: false, node: true, nomen: true, sub: true */
/*global */
// Copyright 2012 Yaco Sistemas S.L.
//
// Developed by Yaco Sistemas <[email protected]>
//
// Licensed under the EUPL, Version 1.1 or – as soon they
// will be approved by the European Commission - subsequent
// versions of the EUPL (the "Licence");
// You may not use this work except in compliance with the
// Licence.
// You may obtain a copy of the Licence at:
//
// http://joinup.ec.europa.eu/software/page/eupl
//
// Unless required by applicable law or agreed to in
// writing, software distributed under the Licence is
// distributed on an "AS IS" basis,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied.
// See the Licence for the specific language governing
// permissions and limitations under the Licence.
/**
* Module dependencies.
*/
var express = require('express'),
lingua = require('lingua'),
Memcached = require('memcached'),
viewer = require('./routes/viewer'),
png = require('./routes/png'),
svg = require('./routes/svg'),
kml = require('./routes/kml'),
settings = require('./settings'),
dirname = require('path').dirname,
readFileSync = require('fs').readFileSync,
globalOpts = settings.settings.global,
app = module.exports = express.createServer(),
configureApp,
initMemcached;
// Utilities
initMemcached = function (client, server, app) {
"use strict";
// TODO what if there are more than just one server
client.connect(server, function (err, conn) {
if (err) {
console.error('Error connecting to memcached');
console.error(err);
console.error('Cache won\'t be available');
app.set('memcached', null);
} else {
console.log('Connected to memcached');
console.log(conn.server);
}
});
};
// Configuration
app.configure(function () {
"use strict";
app.set('views', __dirname + '/views');
app.set('view engine', 'html');
app.register('.html', require('jqtpl').express);
app.use(lingua(app, {
defaultLocale: 'en',
path: __dirname + '/i18n'
}));
app.set('debug_charts', globalOpts.debug);
app.set('viewer_host', globalOpts.host);
app.set('siteLogo', globalOpts.logo);
app.set('siteTitle', globalOpts.title);
app.set('staticUrl', globalOpts.staticUrl);
app.use(express.bodyParser());
app.use(express.methodOverride());
// static is not in dot notation because of JSLint
app.use(express['static'](__dirname + '/public'));
app.use(app.router);
});
configureApp = function (app, opts) {
"use strict";
app.set('sparql endpoint', opts.sparqlEndpoint);
app.set('memcached', new Memcached(opts.memcachedServer));
app.set('memcached lifetime', opts.memcachedLifetime);
app.set('bar', opts.bar);
app.set('pie', opts.pie);
app.set('line', opts.line);
app.set('timeline', opts.timeline);
app.set('map', opts.map);
app.set('mapea', opts.mapea);
};
app.configure('development', function () {
"use strict";
app.use(express.errorHandler({
dumpExceptions: true,
showStack: true
}));
configureApp(app, settings.settings.development);
});
app.configure('production', function () {
"use strict";
app.use(express.errorHandler());
configureApp(app, settings.settings.production);
});
// Routes
app.get('/viewer/', viewer.dataViewer);
app.get('/png/', png.get);
app.get('/svg/', svg.get);
app.get('/kml/', kml.get);
// Start server
app.listen(globalOpts.port);
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);