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

add support for port passed in domain using cli like "--domain localhost:3000" #136

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
11 changes: 9 additions & 2 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ export default () => {
domain = 'localhost',
outputDir = buildDir,
} = program.optsObj

var port = 0, domain_final = domain
if(domain.split(':')[1]){
port = domain.split(':')[1].split('/')[0]
domain_final = domain.split(':')[0]
}
console.log("domain_final = ",domain_final,"port = ",port)

const pkg = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'package.json')))
const basename = ((p) => p.endsWith('/') ? p : p + '/')(pkg.homepage ? url.parse(pkg.homepage).pathname : '')
Expand All @@ -39,9 +46,9 @@ export default () => {
const writer = new Writer(buildDirPath, outputDirPath)
writer.move('index.html', '200.html')

const server = new Server(buildDirPath, basename, 0, pkg.proxy)
const server = new Server(buildDirPath, basename, port, pkg.proxy)
server.start().then(() => {
const crawler = new Crawler(`http://${domain}:${server.port()}${basename}`, options.snapshotDelay, options)
const crawler = new Crawler(`http://${domain_final}:${server.port()}${basename}`, options.snapshotDelay, options)
return crawler.crawl(({ urlPath, html }) => {
if (!urlPath.startsWith(basename)) {
console.log(`❗ Refusing to crawl ${urlPath} because it is outside of the ${basename} sub-folder`)
Expand Down