docsify/app.js

54 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-11-26 18:37:17 +08:00
var serveStatic = require('serve-static')
var http = require('http')
var fs = require('fs')
2017-05-30 01:25:52 +08:00
var Renderer = require('./packages/docsify-server-renderer/build.js')
var renderer = new Renderer({
template: `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>docsify</title>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="/themes/vue.css" title="vue">
</head>
<body>
<!--inject-app-->
<!--inject-config-->
<script src="/lib/docsify.js"></script>
</body>
</html>`,
config: {
name: 'docsify',
repo: 'qingwei-li/docsify',
2017-05-30 03:48:29 +08:00
basePath: 'https://docsify.js.org/',
2017-05-30 01:25:52 +08:00
loadNavbar: true,
loadSidebar: true,
subMaxLevel: 3,
2017-05-30 03:48:29 +08:00
auto2top: true,
alias: {
'/de-de/changelog': '/changelog',
'/zh-cn/changelog': '/changelog',
2017-09-22 10:07:10 +08:00
'/changelog':
'https://raw.githubusercontent.com/QingWei-Li/docsify/master/CHANGELOG'
2017-05-30 03:48:29 +08:00
}
2017-05-30 01:25:52 +08:00
},
path: './'
})
2016-11-26 18:37:17 +08:00
2017-09-22 10:07:10 +08:00
http
.createServer(function (req, res) {
serveStatic('.')(req, res, function () {
// TEST SSR
// renderer.renderToString(req.url)
2017-05-30 03:48:29 +08:00
// .then(html => res.end(html))
2017-05-30 01:25:52 +08:00
2017-09-22 10:07:10 +08:00
res.writeHead(404, { 'Content-Type': 'text/html' })
res.end(fs.readFileSync('dev.html'))
})
2016-11-26 18:37:17 +08:00
})
2017-09-22 10:07:10 +08:00
.listen(3000, '0.0.0.0')
2016-11-26 18:37:17 +08:00
console.log(`\nListening at http://0.0.0.0:3000\n`)