Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] : Serve several static paths #89

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
gigaga authored Jan 17, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 08be35893bf7c7aba464313d69bee28b5d684631
62 changes: 36 additions & 26 deletions lib/commands/serve.js
Original file line number Diff line number Diff line change
@@ -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)