Skip to content

Commit

Permalink
fix: support single http-get urls, close #209
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Sep 13, 2019
1 parent 6423340 commit 8692100
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ script:
- npm run demo5
- npm run demo6
- npm run demo7
# hmm why are some demos skipped?
- npm run demo11
- START_SERVER_AND_TEST_INSECURE=1 npm run demo9
- npm run demo-cross-env
- npm run demo-commands
Expand Down
16 changes: 16 additions & 0 deletions src/utils-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,22 @@ describe('utils', () => {
la(isUrlOrPort('http://foo.com'))
la(isUrlOrPort('http://foo.com/bar/baz.html'))
la(isUrlOrPort('http://localhost:6000'))
la(isUrlOrPort('https://google.com'))
})

it('allows url with http-get', () => {
la(isUrlOrPort('http-get://localhost'))
la(isUrlOrPort('http-get://foo.com'))
la(isUrlOrPort('http-get://foo.com/bar/baz.html'))
la(isUrlOrPort('http-get://localhost:6000'))
})

it('allows url with https-head', () => {
la(isUrlOrPort('https-head://localhost:6000'))
})

it('allows url with https-options', () => {
la(isUrlOrPort('https-head://foo'))
})

it('allows port number or string', () => {
Expand Down
8 changes: 8 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,21 @@ const isPackageScriptName = command => {
return Boolean(packageJson.scripts[command])
}

const isWaitOnUrl = s => /^https?-(?:get|head|options)/.test(s)

const isUrlOrPort = input => {
const str = is.string(input) ? input.split('|') : [input]

return str.every(s => {
if (is.url(s)) {
return s
}
// wait-on allows specifying HTTP verb to use instead of default HEAD
// and the format then is like "http-get://domain.com" to use GET
if (isWaitOnUrl(s)) {
return s
}

if (is.number(s)) {
return is.port(s)
}
Expand Down

0 comments on commit 8692100

Please sign in to comment.