-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
38 lines (29 loc) · 922 Bytes
/
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
'use strict';
var express = require('express');
var http = require('http');
var join = require('path').join;
var fs = require('fs');
global.CONFIG = {
wwwroot: join(__dirname, '../spmjs.io/data')
};
var app = express();
app.set('port', 3002);
app.get('/:name/examples/*', function(req, res, next) {
if (fs.existsSync(join(CONFIG.wwwroot, 'docs', req.params.name))) {
res.redirect('/' + req.params.name + '/latest' + '/examples/');
} else {
next();
}
});
app.get('/:name/:version/*', require('./docs'));
app.get('/:name', function(req, res, next) {
if (fs.existsSync(join(CONFIG.wwwroot, 'docs', req.params.name))) {
res.redirect('/' + req.params.name + '/latest');
} else {
next();
}
});
app.get('/*', express.static(join(CONFIG.wwwroot, 'docs')));
http.createServer(app).listen(app.get('port'), function() {
console.log('Express server listening on port ' + app.get('port'));
});