forked from keystonejs/keystonejs-site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
76 lines (60 loc) · 2.14 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
/**
* This script launches the KeystoneJS Docs website using express.
*/
var _ = require('lodash');
var errorHandler = require('errorhandler');
var express = require('express');
var favicon = require('serve-favicon');
var less = require('less-middleware');
var logger = require('morgan');
var content = require('./content');
var classReference = require('./content/common/apiMarked');
//var marked = _.cloneDeep(classReference._marked);
//classReference.getApi(marked);
function view(view, options) {
return function(req, res, next) {
options.pretty = true;
delete options.apidocs;
options.prefix = (options.language === 'en') ? '/' : '/' + options.language + '/';
_.extend(options, content.languages[options.language]);
if(_.contains(['0.2.x','0.3.x','0.4.x'], options.api)) {
var sendMarked = _.cloneDeep(classReference._marked[options.language][options.api]);
classReference.getApi(sendMarked, options.language, options.api, function(err, marked) {
options.apidocs = sendMarked;
res.render(options.language + '/pages/' + view, options);
});
} else {
res.render(options.language + '/pages/' + view, options);
}
}
}
var app = express();
app.set('port', process.env.PORT || 8080);
app.set('views', 'content');
app.set('view engine', 'jade');
app.use(favicon('public/favicon.ico'));
app.use(less('public'));
app.use(express.static('public'));
app.use(logger('dev'));
// disable cache, safari workaround
// see http://stackoverflow.com/questions/18811286/nodejs-express-cache-and-304-status-code
app.use(function(req, res, next) {
res.header("Cache-Control", "no-cache, no-store, must-revalidate");
res.header("Pragma", "no-cache");
res.header("Expires", 0);
next();
});
// Set up locals and routes
app.locals.languages = content.languages;
app.locals.version = require('./package.json').version;
_.each(content.routes, function(options) {
app.get(options.path, view(options.template, options));
});
app.use(function(req, res, next) {
res.status(404).render('404');
});
app.use(errorHandler());
// Start server
app.listen(app.get('port'), function() {
console.log('Keystone docs are available on port ' + app.get('port'));
});