mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-02-21 07:29:37 +01:00
chore: remove axios in favor of fetch
xhr is not in the wave anymore
This commit is contained in:
parent
b9a6edf9b0
commit
fef7ee75e8
@ -51,7 +51,6 @@
|
|||||||
"@commitlint/config-conventional": "6.1.3",
|
"@commitlint/config-conventional": "6.1.3",
|
||||||
"@commitlint/travis-cli": "6.1.3",
|
"@commitlint/travis-cli": "6.1.3",
|
||||||
"@verdaccio/types": "2.0.2",
|
"@verdaccio/types": "2.0.2",
|
||||||
"axios": "0.18.0",
|
|
||||||
"babel-cli": "6.26.0",
|
"babel-cli": "6.26.0",
|
||||||
"babel-core": "6.26.0",
|
"babel-core": "6.26.0",
|
||||||
"babel-eslint": "8.2.2",
|
"babel-eslint": "8.2.2",
|
||||||
@ -129,7 +128,8 @@
|
|||||||
"verdaccio-memory": "0.0.6",
|
"verdaccio-memory": "0.0.6",
|
||||||
"webpack": "3.10.0",
|
"webpack": "3.10.0",
|
||||||
"webpack-dev-server": "2.11.1",
|
"webpack-dev-server": "2.11.1",
|
||||||
"webpack-merge": "4.1.2"
|
"webpack-merge": "4.1.2",
|
||||||
|
"whatwg-fetch": "2.0.3"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"private",
|
"private",
|
||||||
|
@ -7,11 +7,11 @@ import {Link} from 'react-router-dom';
|
|||||||
|
|
||||||
import API from '../../../utils/api';
|
import API from '../../../utils/api';
|
||||||
import storage from '../../../utils/storage';
|
import storage from '../../../utils/storage';
|
||||||
|
import {getRegistryURL} from '../../../utils/url';
|
||||||
|
|
||||||
import classes from './header.scss';
|
import classes from './header.scss';
|
||||||
import './logo.png';
|
import './logo.png';
|
||||||
import {getRegistryURL} from '../../../utils/url';
|
|
||||||
|
|
||||||
export default class Header extends React.Component {
|
export default class Header extends React.Component {
|
||||||
state = {
|
state = {
|
||||||
@ -43,9 +43,9 @@ export default class Header extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
API.get('logo')
|
API.request('logo')
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
this.setState({logo: response.data});
|
this.setState({logo: response.url});
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
throw new Error(error);
|
throw new Error(error);
|
||||||
@ -62,15 +62,15 @@ export default class Header extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let resp = await API.post(`login`, {
|
let resp = await API.request(`login`, 'POST', {
|
||||||
data: {
|
data: {
|
||||||
username: this.state.username,
|
username: this.state.username,
|
||||||
password: this.state.password
|
password: this.state.password
|
||||||
}
|
}
|
||||||
});
|
}).then((response) => response.json());
|
||||||
|
|
||||||
storage.setItem('token', resp.data.token);
|
storage.setItem('token', resp.token);
|
||||||
storage.setItem('username', resp.data.username);
|
storage.setItem('username', resp.username);
|
||||||
location.reload();
|
location.reload();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const errorObj = {
|
const errorObj = {
|
||||||
@ -78,7 +78,7 @@ export default class Header extends React.Component {
|
|||||||
type: 'error'
|
type: 'error'
|
||||||
};
|
};
|
||||||
if (get(e, 'response.status', 0) === 401) {
|
if (get(e, 'response.status', 0) === 401) {
|
||||||
errorObj.description = e.response.data.error;
|
errorObj.description = e.response.error;
|
||||||
} else {
|
} else {
|
||||||
errorObj.description = e.message;
|
errorObj.description = e.message;
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ export default class PackageSidebar extends React.Component {
|
|||||||
let packageMeta;
|
let packageMeta;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
packageMeta = (await API.get(`sidebar/${packageName}`)).data;
|
packageMeta = await API.request(`sidebar/${packageName}`, 'GET').then((response) => response.json());
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.setState({
|
this.setState({
|
||||||
failed: true
|
failed: true
|
||||||
|
@ -47,9 +47,9 @@ export default class Detail extends React.Component {
|
|||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const resp = await API.get(`package/readme/${packageName}`);
|
const resp = await API.request(`package/readme/${packageName}`, 'GET').then((response) => response.text());
|
||||||
this.setState({
|
this.setState({
|
||||||
readMe: resp.data
|
readMe: resp
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.setState({
|
this.setState({
|
||||||
|
@ -52,11 +52,11 @@ export default class Home extends React.Component {
|
|||||||
|
|
||||||
async loadPackages() {
|
async loadPackages() {
|
||||||
try {
|
try {
|
||||||
this.req = await API.get('packages');
|
this.req = await API.request('packages', 'GET').then((response) => response.json());
|
||||||
|
|
||||||
if (this.state.query === '') {
|
if (this.state.query === '') {
|
||||||
this.setState({
|
this.setState({
|
||||||
packages: this.req.data,
|
packages: this.req,
|
||||||
loading: false
|
loading: false
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -71,12 +71,12 @@ export default class Home extends React.Component {
|
|||||||
|
|
||||||
async searchPackage(query) {
|
async searchPackage(query) {
|
||||||
try {
|
try {
|
||||||
this.req = await API.get(`/search/${query}`);
|
this.req = await API.request(`/search/${query}`, 'GET').then((response) => response.json());
|
||||||
|
|
||||||
// Implement cancel feature later
|
// Implement cancel feature later
|
||||||
if (this.state.query === query) {
|
if (this.state.query === query) {
|
||||||
this.setState({
|
this.setState({
|
||||||
packages: this.req.data,
|
packages: this.req,
|
||||||
fistTime: false,
|
fistTime: false,
|
||||||
loading: false
|
loading: false
|
||||||
});
|
});
|
||||||
|
@ -1,34 +1,27 @@
|
|||||||
import storage from './storage';
|
import storage from './storage';
|
||||||
import axios from 'axios';
|
|
||||||
|
|
||||||
class API {
|
class API {
|
||||||
constructor() {
|
request(url, method = 'GET', options = {}) {
|
||||||
['get', 'delete', 'post', 'put', 'patch'].map((method) => {
|
if (!window.VERDACCIO_API_URL) {
|
||||||
this[method] = (url, options = {}) => {
|
throw new Error('VERDACCIO_API_URL is not defined!');
|
||||||
if (!window.VERDACCIO_API_URL) {
|
}
|
||||||
throw new Error('VERDACCIO_API_URL is not defined!');
|
|
||||||
}
|
|
||||||
|
|
||||||
const token = storage.getItem('token');
|
const token = storage.getItem('token');
|
||||||
if (token) {
|
if (token) {
|
||||||
if (!options.headers) options.headers = {};
|
if (!options.headers) options.headers = {};
|
||||||
|
|
||||||
options.headers.authorization = token;
|
options.headers.authorization = token;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!['http://', 'https://', '//'].some((prefix) => url.startsWith(prefix))) {
|
if (!['http://', 'https://', '//'].some((prefix) => url.startsWith(prefix))) {
|
||||||
url = window.VERDACCIO_API_URL + url;
|
url = window.VERDACCIO_API_URL + url;
|
||||||
}
|
}
|
||||||
|
|
||||||
return axios.request({
|
return fetch(url, {
|
||||||
method,
|
method,
|
||||||
url,
|
...options
|
||||||
...options
|
});
|
||||||
});
|
}
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export default new API();
|
export default new API();
|
||||||
|
@ -10,6 +10,7 @@ export default {
|
|||||||
...baseConfig,
|
...baseConfig,
|
||||||
entry: {
|
entry: {
|
||||||
main: [
|
main: [
|
||||||
|
'whatwg-fetch',
|
||||||
'react-hot-loader/patch',
|
'react-hot-loader/patch',
|
||||||
'webpack-dev-server/client?http://localhost:4872',
|
'webpack-dev-server/client?http://localhost:4872',
|
||||||
'webpack/hot/only-dev-server',
|
'webpack/hot/only-dev-server',
|
||||||
@ -22,6 +23,8 @@ export default {
|
|||||||
publicPath: '/',
|
publicPath: '/',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
devtool: 'cheap-module-eval-source-map',
|
||||||
|
|
||||||
plugins: [
|
plugins: [
|
||||||
new webpack.DefinePlugin({
|
new webpack.DefinePlugin({
|
||||||
__DEBUG__: true,
|
__DEBUG__: true,
|
||||||
|
@ -9,7 +9,7 @@ import getPackageVersion from './getPackageVersion';
|
|||||||
|
|
||||||
const prodConf = {
|
const prodConf = {
|
||||||
entry: {
|
entry: {
|
||||||
main: ['babel-polyfill', `${env.SRC_ROOT}/webui/src/index.js`],
|
main: ['babel-polyfill', 'whatwg-fetch', `${env.SRC_ROOT}/webui/src/index.js`],
|
||||||
},
|
},
|
||||||
|
|
||||||
module: {
|
module: {
|
||||||
|
BIN
yarn.lock
BIN
yarn.lock
Binary file not shown.
Loading…
Reference in New Issue
Block a user