Skip to content
This repository has been archived by the owner on Jan 16, 2022. It is now read-only.

Commit

Permalink
fix: generate correct registry URL (#413)
Browse files Browse the repository at this point in the history
* Revert "Revert "fix(#300): correctly reference registry url from options" (#311)"

This reverts commit d955268.

* fix: generate full URL from path
  • Loading branch information
DanielRuf authored and juanpicado committed Jan 9, 2020
1 parent 3fd0154 commit 6b322ad
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion jest/jestEnvironment.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
require.requireActual('babel/polyfill');
jest.requireActual('babel/polyfill');
5 changes: 2 additions & 3 deletions jest/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ import Adapter from 'enzyme-adapter-react-16';
import { GlobalWithFetchMock } from 'jest-fetch-mock';
import 'mutationobserver-shim';

// @ts-ignore : Only a void function can be called with the 'new' keyword
configure({ adapter: new Adapter() });

// @ts-ignore : Property '__APP_VERSION__' does not exist on type 'Global'.
global.__APP_VERSION__ = '1.0.0';
// @ts-ignore : Property '__VERDACCIO_BASENAME_UI_OPTIONS' does not exist on type 'Global'.
global.__VERDACCIO_BASENAME_UI_OPTIONS = {};

global.__VERDACCIO_BASENAME_UI_OPTIONS = { base: 'http://localhost' };
// @ts-ignore : Property 'VERDACCIO_API_URL' does not exist on type 'Global'.
global.VERDACCIO_API_URL = 'https://verdaccio.tld';

const customGlobal: GlobalWithFetchMock = global as GlobalWithFetchMock;
Expand Down
10 changes: 7 additions & 3 deletions src/utils/url.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ describe('utils', () => {
expect(isEmail('')).toBeFalsy();
});

test('getRegistryURL() - should keep slash if location is a sub directory', () => {
test('getRegistryURL() - should not change when location change', () => {
expect(getRegistryURL()).toBe('http://localhost');
history.pushState({}, 'page title', '/-/web/detail');
expect(getRegistryURL()).toBe('http://localhost/-/web/detail');
expect(getRegistryURL()).toBe('http://localhost');
history.pushState({}, 'page title', '/');
});

test('getRegistryURL() - should not add slash if location is not a sub directory', () => {
test('getRegistryURL() - should change when UI options change', () => {
expect(getRegistryURL()).toBe('http://localhost');
window.__VERDACCIO_BASENAME_UI_OPTIONS.base = 'http://localhost/test';
expect(getRegistryURL()).toBe('http://localhost/test');
window.__VERDACCIO_BASENAME_UI_OPTIONS.base = 'http://localhost';
});
});

Expand Down
3 changes: 1 addition & 2 deletions src/utils/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ export function isEmail(email: string): boolean {
}

export function getRegistryURL(): string {
// Don't add slash if it's not a sub directory
return `${location.origin}${location.pathname === '/' ? '' : location.pathname}`;
return window.__VERDACCIO_BASENAME_UI_OPTIONS.base;
}

export function extractFileName(url: string): string {
Expand Down
2 changes: 1 addition & 1 deletion tools/webpack.dev.config.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default {
}),
new HTMLWebpackPlugin({
__UI_OPTIONS: JSON.stringify({
base: '/',
base: new URL('/', 'https://localhost:4872'),
}),
title: 'Verdaccio Dev UI',
scope: '',
Expand Down

0 comments on commit 6b322ad

Please sign in to comment.