Merge pull request #101 from griffithtp/fix/76_download-button-hidden-for-localhost

fix: 76 download button hidden for localhost
This commit is contained in:
Juan Picado @jotadeveloper 2019-07-14 14:27:44 +02:00 committed by GitHub
commit cad5ac91e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 18 deletions

View File

@ -23,6 +23,7 @@
"@types/react": "16.8.16",
"@types/react-dom": "16.8.4",
"@types/react-router-dom": "4.3.2",
"@types/validator": "10.11.1",
"@verdaccio/babel-preset": "0.2.1",
"@verdaccio/eslint-config": "0.0.1",
"@verdaccio/types": "6.1.0",

View File

@ -1,8 +0,0 @@
import { createBrowserHistory } from 'history';
import { getBaseNamePath } from './utils/url';
const history = createBrowserHistory({
basename: getBaseNamePath(),
});
export default history;

View File

@ -2,12 +2,16 @@
import React, { Component, ReactElement } from 'react';
import { Router, Route, Switch } from 'react-router-dom';
import { createBrowserHistory } from 'history';
import { AppContextConsumer, AppStateInterface } from './App/App';
import { asyncComponent } from './utils/asyncComponent';
import history from './history';
import Header from './components/Header';
const history = createBrowserHistory({
basename: window.__VERDACCIO_BASENAME_UI_OPTIONS && window.__VERDACCIO_BASENAME_UI_OPTIONS.url_prefix,
});
const NotFound = asyncComponent(() => import('./components/NotFound'));
const VersionPackage = asyncComponent(() => import('./pages/version/Version'));
const HomePage = asyncComponent(() => import('./pages/home'));

27
src/utils/url.test.ts Normal file
View File

@ -0,0 +1,27 @@
import { isURL, isEmail, getRegistryURL } from './url';
describe('url', () => {
test('isURL() - should return true for localhost', () => {
expect(isURL('http://localhost:8080/bootstrap/-/bootstrap-4.3.1.tgz')).toBeTruthy();
});
test('isURL() - should return false when protocol is missing', () => {
expect(isURL('localhost:8080/bootstrap/-/bootstrap-4.3.1.tgz')).toBeFalsy();
});
test('isEmail() - should return true if valid', () => {
expect(isEmail('email@domain.com')).toBeTruthy();
});
test('isEmail() - should return false if invalid', () => {
expect(isEmail('')).toBeFalsy();
});
test('getRegistryURL() - should keep slash if location is a sub directory', () => {
history.pushState({}, 'page title', '/-/web/detail');
expect(getRegistryURL()).toBe('http://localhost/-/web/detail');
history.pushState({}, 'page title', '/');
});
test('getRegistryURL() - should not add slash if location is not a sub directory', () => {
expect(getRegistryURL()).toBe('http://localhost');
});
});

View File

@ -2,10 +2,11 @@ import isURLValidator from 'validator/lib/isURL';
import isEmailValidator from 'validator/lib/isEmail';
import '../../types';
export function isURL(url): boolean {
export function isURL(url: string): boolean {
return isURLValidator(url || '', {
protocols: ['http', 'https', 'git+https'],
require_protocol: true,
require_tld: false,
});
}
@ -17,11 +18,3 @@ export function getRegistryURL(): string {
// Don't add slash if it's not a sub directory
return `${location.origin}${location.pathname === '/' ? '' : location.pathname}`;
}
export function getBaseNamePath(): string {
return window.__VERDACCIO_BASENAME_UI_OPTIONS && window.__VERDACCIO_BASENAME_UI_OPTIONS.url_prefix;
}
export function getRootPath(): string {
return window.__VERDACCIO_BASENAME_UI_OPTIONS && window.__VERDACCIO_BASENAME_UI_OPTIONS.base;
}

View File

@ -1743,6 +1743,11 @@
resolved "https://registry.verdaccio.org/@types%2funist/-/unist-2.0.3.tgz#9c088679876f374eb5983f150d4787aa6fb32d7e"
integrity sha512-FvUupuM3rlRsRtCN+fDudtmytGO6iHJuuRKS1Ss0pG5z8oX0diNEw94UEL7hgDbpN94rgaK5R7sWm6RrSkZuAQ==
"@types/validator@10.11.1":
version "10.11.1"
resolved "https://registry.npmjs.org/@types/validator/-/validator-10.11.1.tgz#76e983ce155261838463b73728856cf8bc628d53"
integrity sha512-bVhLqvb+5xUNWRFnuuecRVISTvsG6AdhrB2kb/tChgtuTTqARqlQ3rLhOPy8cINZEUB8PkR+goyWF6fWxg4iSw==
"@types/vfile-message@*":
version "1.0.1"
resolved "https://registry.verdaccio.org/@types%2fvfile-message/-/vfile-message-1.0.1.tgz#e1e9895cc6b36c462d4244e64e6d0b6eaf65355a"