forked from koopjs/koop-app-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
65 lines (56 loc) · 1.74 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
var express = require('express');
var cors = require('cors');
var config = require('config');
var koop = require('koop')(config);
var socrata = require('koop-socrata');
var ckan = require('koop-ckan');
var github = require('koop-github');
var agol = require('koop-agol');
var gist = require('koop-gist');
var path = require('path');
var app = express();
var server;
// In production, in-memory cache storage is not recommended.
// We recommend using PostGIS as the cache engine.
// var pgCache = require('koop-pgcache');
// koop.registerCache(pgCache);
// use HTTPS if it's included in the configuration
if (config.https_server &&
config.https_server.private_key &&
config.https_server.public_key) {
var https = require('https');
var fs = require('fs');
var options = {
key: fs.readFileSync(config.https_server.private_key),
cert: fs.readFileSync(config.https_server.public_key)
};
} else {
// use http module by default
var http = require('http');
}
// register koop providers
koop.register(socrata);
koop.register(ckan);
koop.register(github);
koop.register(gist);
koop.register(agol);
app.set('port', process.env.PORT || config.server.port || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(cors()); // add CORS support (recommended)
app.use(koop); // add koop middleware
app.get('/status', function (req, res) {
res.json(koop.status);
});
app.get('/', function (req, res) {
res.render('index', { status: koop.status });
});
if (config.https_server) {
server = https.createServer(options, app);
} else {
server = http.createServer(app);
}
// start the server
server.listen(app.get('port'), function () {
console.log('Express koop server listening on port ' + app.get('port'));
})