Skip to content

Commit

Permalink
fix: remove context
Browse files Browse the repository at this point in the history
  • Loading branch information
QingWei-Li committed May 29, 2017
1 parent 3a4e31e commit 8b3679f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
29 changes: 17 additions & 12 deletions lib/commands/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ var defaultConfig = {
<!--inject-config-->
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
</body>
</html>`,
context: './'
</html>`
}

function loadConfig (config) {
Expand All @@ -37,13 +36,12 @@ function loadConfig (config) {
module.exports = function (path, configFile, port) {
let config = defaultConfig
const pkg = util.pkg()
let ctx = util.cwd()
let ctx = util.cwd('.')

path = path || './'

if (configFile) {
config = loadConfig(configFile)
ctx = config.context || ctx
config.template = /\.html$/.test(config.template)
? util.read(util.resolve(ctx, config.template))
: config.template
Expand All @@ -57,16 +55,23 @@ module.exports = function (path, configFile, port) {
var renderer = new Renderer(Object.assign(defaultConfig, config))
var server = connect()

server.use(serveStatic(path))
server.use(function(req, res) {
renderer.renderToString(req.url)
.then(function (html) {
res.end(html)
})
.catch(function (err) {
res.end(util.read(util.resolve(path, 'index.html')))
})
serveStatic(path)(req, res, function () {
if (/\.(jpg|jpeg|gif|png|svg|ico|mp4|webm|ogg|ogv|js|css|md)(?:\?v=[0-9.]+)?$/.test(req.url)) {
res.writeHead(404)
res.end()
}
renderer.renderToString(req.url)
.then(function (html) {
res.end(html)
})
.catch(function (err) {
res.writeHead(404)
res.end()
})
})
})
server.use(serveStatic(path))
server.listen(port || 4000)

const msg = '\n'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"connect-livereload": "^0.6.0",
"cp-file": "^4.1.1",
"docsify": ">=3",
"docsify-server-renderer": "^4.0.0",
"docsify-server-renderer": "^4.0.1",
"fs-extra": "^2.1.2",
"livereload": "^0.6.2",
"open": "^0.0.5",
Expand Down

0 comments on commit 8b3679f

Please sign in to comment.