Skip to content
Open
Changes from 1 commit
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
Next Next commit
Serve several static paths
  • Loading branch information
gigaga authored Jan 17, 2020
commit 08be35893bf7c7aba464313d69bee28b5d684631
62 changes: 36 additions & 26 deletions lib/commands/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,48 +25,58 @@ 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
}
server.use(serveStatic(path, { index: indexName }));
});

if (!exists(indexFile)) {
if (!indexFileFound) {
const msg =
'\nNo docs found ' +
"\nNo docs found " +
indexFile +
'\nPlease run ' +
chalk.green('docsify init') +
' first.\n'
console.log(msg)
process.exit(0)
"\nPlease run " +
chalk.green("docsify init") +
" first.\n";
console.log(msg);
process.exit(0);
}

const server = connect()
server.use(
livereload({
port: livereloadPort
})
)
server.use(serveStatic(path, {index: indexName}))
server.listen(port)


server.listen(port);
lrserver
.createServer({
extraExts: ['md'],
exclusions: ['node_modules/'],
extraExts: ["md"],
exclusions: ["node_modules/"],
port: livereloadPort
})
.watch(path)
.watch(path.split(","));

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

const msg =
'\nServing ' +
"\nServing " +
chalk.green(`${path}`) +
' now.\n' +
'Listening at ' +
" now.\n" +
"Listening at " +
chalk.green(`http://localhost:${port}`) +
'\n'
console.log(msg)
"\n";
console.log(msg);
})
.catch(err => {
console.error(err.message)
Expand Down