forked from oskariorg/oskari-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
88 lines (76 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
var express = require('express');
var path = require('path');
var fs = require('fs');
var asset = require('static-asset');
var routes = require('./routes');
var port = process.env.NODE_PORT || 3003;
var environment = process.env.NODE_ENV || 'development';
var publicDir = path.join(__dirname, 'public');
var app = express();
// Configurations
app.set('port', port);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
app.set('view options', {
layout: false
});
app.use(asset(publicDir));
app.use(express.static(publicDir));
app.get('/guides', routes.guides);
app.get('/guides/*', routes.md);
app.get('/documentation', routes.documentation);
// redirect requests for old bundledocs to the new /api/bundles
app.get('/documentation/bundles', function (req, res) {
res.redirect('/api/bundles');
});
app.get('/documentation/bundles/*', function (req, res) {
res.redirect('/api/bundles');
});
app.get('/documentation/*', routes.md);
// The route is just meant to be used as a preview and should not be used for linking from other sites.
// Once we move the contents to intended places we can remove this route completely
app.get('/community/*', routes.community);
app.get('/download', routes.download);
app.get('/about', routes.about);
app.get('/oskari', routes.oskari);
app.get('/gallery', routes.gallery);
app.get('/gallery/*', routes.gallery);
// new api doc end points
app.get('/api', routes.apiSelection);
app.get('/api/bundles', routes.bundlesPage);
app.get('/api/requests', routes.requestsPage);
app.get('/api/events', routes.eventsPage);
app.get('/api/bundles.json', routes.bundlesJSON);
app.get('/api/requests.json', routes.requestsJSON);
app.get('/api/events.json', routes.eventsJSON);
app.get('/apidoc/:ver/*', function(req, res) {
routes.apiDoc(req.params.ver, req.params[0], function(content) {
if(!content) {
res.sendStatus(404);
return;
}
res.send(content);
})
});
// for handling images linked in bundle docs
var apiResDir = path.join(__dirname, 'generated/api')
app.use(asset(apiResDir));
app.use('/apires', express.static(apiResDir));
// generated jsdocs
app.use('/jsdoc', routes.checkLatestVersion);
app.use('/jsdoc/*', routes.checkLatestVersion);
app.use('/jsdoc', express.static(path.join(__dirname, 'generated/jsdoc')));
// generated db documentation
app.use('/db', express.static(path.join(__dirname, 'generated/db')));
app.get('/', routes.root);
app.use(function(err, req, res, next) {
console.error(err);
next(err);
});
/*
process.on('uncaughtException', function (error) {
console.log(error.stack);
});
*/
app.listen(app.get('port'));
console.log('Listening on port ' + app.get('port') + ' on ' + environment + ' environment');