Skip to content

Commit 30e89cb

Browse files
committed
Maintain the prior behaviour of navy.url
If the given service isn't running, return a postulated url instead.
1 parent 70242bf commit 30e89cb

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

packages/navy/src/navy/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {loadPlugins} from './plugin-interface'
1414
import {middlewareRunner} from './middleware'
1515
import {reconfigureHTTPProxy} from '../http-proxy'
1616
import {getExternalIP} from '../util/external-ip'
17-
import {getUrlFromService} from '../util/service-host'
17+
import {createUrlForService, getUrlFromService} from '../util/service-host'
1818

1919
import type {Driver, CreateDriver} from '../driver'
2020
import type {ConfigProvider, CreateConfigProvider} from '../config-provider'
@@ -520,7 +520,7 @@ export class Navy extends EventEmitter2 {
520520
*/
521521
async url(service: string): Promise<?string> {
522522
const ps = await (await this.safeGetDriver()).ps(service)
523-
return getUrlFromService(ps.pop())
523+
return getUrlFromService(ps.pop()) || createUrlForService(service, this.normalisedName, await this.externalIP())
524524
}
525525

526526
/**

packages/navy/src/util/__tests__/service-host.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-env mocha */
22

33
import {expect} from 'chai'
4-
import {getNIPSubdomain, getUrlFromService, createHostForService} from '../service-host'
4+
import {getNIPSubdomain, getUrlFromService, createHostForService, createUrlForService} from '../service-host'
55

66
describe('service-host', function () {
77

@@ -20,13 +20,20 @@ describe('service-host', function () {
2020

2121
describe('createHostForService', function () {
2222

23-
it('should return the correct url host for a service', async function () {
23+
it('should return the correct host for a service', async function () {
2424
expect(await createHostForService('someservice', 'mynavy', '127.0.0.1')).to.equal('someservice.mynavy.127.0.0.1.nip.io')
2525
expect(await createHostForService('someservice', 'mynavy', '192.168.1.10')).to.equal('someservice.mynavy.192.168.1.10.nip.io')
2626
})
2727

2828
})
2929

30+
describe('createUrlForService', function () {
31+
32+
it('should return the correct url for a service', async function () {
33+
expect(await createUrlForService('someservice', 'mynavy', '192.168.99.100')).to.equal('http://someservice.mynavy.192.168.99.100.nip.io')
34+
})
35+
})
36+
3037
describe('getUrlFromService', function () {
3138

3239
it('should extract the host from service ENV config', function () {

packages/navy/src/util/service-host.js

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export async function createHostForService(service: string, navyNormalisedName:
2121
return `${service}.${navyNormalisedName}.${process.env.NAVY_EXTERNAL_SUBDOMAIN || await getNIPSubdomain(externalIP)}`
2222
}
2323

24+
export async function createUrlForService(service: string, navyNormalisedName: string, externalIP: string) {
25+
return `http://${await createHostForService(service, navyNormalisedName, externalIP)}`
26+
}
27+
2428
export function getUrlFromService(service: Service) {
2529
if (!service || !service.raw || !service.raw.Config || !service.raw.Config.Env) {
2630
return null

0 commit comments

Comments
 (0)