Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions lib/commands/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,26 @@ module.exports = function (
livereloadPort = p
})
.then(_ => {
path = resolve(path || '.')
const indexFile = resolve(path, indexName || 'index.html')
const server = connect()
server.use(
livereload({
port: livereloadPort
})
)

let indexFileFound = false
let indexFile
path.split(',').forEach(path => {
path = resolve(path || ',')
indexFile = resolve(path, indexName || 'index.html')
if (exists(indexFile)) {
indexFileFound = true
}

if (!exists(indexFile)) {
server.use(serveStatic(path, {index: indexName}))
})

if (!indexFileFound) {
const msg =
'\nNo docs found ' +
indexFile +
Expand All @@ -39,21 +55,14 @@ module.exports = function (
process.exit(0)
}

const server = connect()
server.use(
livereload({
port: livereloadPort
})
)
server.use(serveStatic(path, {index: indexName}))
server.listen(port)
lrserver
.createServer({
extraExts: ['md'],
exclusions: ['node_modules/'],
port: livereloadPort
})
.watch(path)
.watch(path.split(','))

if (openInBrowser) {
open(`http://localhost:${port}`)
Expand Down