Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/lib/get-api-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const parseLocalUrl = (couchUrl) => {
const doParse = (unparsed) => {
const parsed = new url.URL(unparsed);
parsed.path = parsed.pathname = '';
parsed.host = `${parsed.hostname}:5988`;
parsed.host = `${parsed.hostname}:${parsed.port || 5988}`;
return new url.URL(url.format(parsed));
};

Expand Down
19 changes: 15 additions & 4 deletions test/lib/get-api-url.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ describe('get-api-url', () => {

it('use environment variable', () => {
const actual = apiUrlLib.getApiUrl({ local: true }, { COUCH_URL: 'http://user:pwd@localhost:5984/db' });
expect(actual).to.deep.equal(new url.URL('http://user:pwd@localhost:5988/medic'));
expect(actual).to.deep.equal(new url.URL('http://user:pwd@localhost:5984/medic'));
});

it('use environment variable with custom port', () => {
const actual = apiUrlLib.getApiUrl({ local: true }, { COUCH_URL: 'http://medic:pass@localhost:61418/medic' });
expect(actual).to.deep.equal(new url.URL('http://medic:pass@localhost:61418/medic'));
});

it('warn if environment variable targets remote', () => {
Expand Down Expand Up @@ -70,11 +75,17 @@ describe('get-api-url', () => {
it('basic', () =>
expect(parseLocalUrl('http://admin:pass@localhost:5988/medic').href).to.eq('http://admin:pass@localhost:5988/'));

it('updates port', () =>
expect(parseLocalUrl('http://admin:pass@localhost:5984/medic').href).to.eq('http://admin:pass@localhost:5988/'));
it('preserves port from COUCH_URL', () =>
expect(parseLocalUrl('http://admin:pass@localhost:5984/medic').href).to.eq('http://admin:pass@localhost:5984/'));

it('preserves custom port from COUCH_URL', () =>
expect(parseLocalUrl('http://admin:pass@localhost:61418/medic').href).to.eq('http://admin:pass@localhost:61418/'));

it('defaults to 5988 when no port specified', () =>
expect(parseLocalUrl('http://admin:pass@localhost/medic').href).to.eq('http://admin:pass@localhost:5988/'));

it('ignores path', () =>
expect(parseLocalUrl('http://admin:pass@localhost:5984/foo').href).to.eq('http://admin:pass@localhost:5988/'));
expect(parseLocalUrl('http://admin:pass@localhost:5984/foo').href).to.eq('http://admin:pass@localhost:5984/'));
});

describe('isLocalhost', () => {
Expand Down