forked from lbovet/docson
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
31 lines (21 loc) · 817 Bytes
/
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
'use strict';
const express = require('express');
const path = require('path');
const serveIndex = require('serve-index');
module.exports = function (options = {}) {
const app = express();
if (!options.directory) options.directory = '.';
app.use(express.static('files'));
let docsonRootDir = path.join(__dirname, '..');
app.use('/docson', express.static(docsonRootDir + '/public'));
app.use('/docson', express.static(docsonRootDir + '/webpack'));
app.get(/\.json$/, function (req, res, next) {
if (req.xhr) return next();
res.redirect('/docson/#' + req.path);
});
app.use('/', serveIndex(options.directory, {
'icons': true
// filter: filename => /\.json$/.test(filename)
}), express.static(options.directory));
return app;
};