Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
@dreamjser/request-axios
Advanced tools
// npm安装
npm i @dreamjser/request-axios
// yarn安装
yarn add @dreamjser/request-axios
// pnpm安装
pnpm add @dreamjser/request-axios
import { getGlobalAxios, getAxios, AllType, OptionsGlobalType } from '@dreamjser/request-axios'
// 获取axios实例,设置全局的配置
const globalOpts: OptionsGlobalType = {
timeout: 30000,
baseURL: GLOBAL_CONFIG.BASE_URL,
}
const axiosInstance = getGlobalAxios(globalOpts)
// 获取axios实例
const axiosInstance = getAxios(opts: AllType, globalInstance)
globalOpts参数可以设置axios的一些全局配置,配置同axios,如下:
{
// baseURL: 'http://api.xxx.com/'
baseURL?: string
// timeout: 15000
timeout?: number
// 上传进度回调
onUploadProgress?: (progressEvent: AxiosProgressEvent) => void
// 下载进度回调
onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void
// headers: {'content-type': 'xxx'}
headers?: object
}
opts参数可以设置axios的配置,配置同axios,同时新增了一些参数如下
{
// 是否显示loading,默认true
slient?:
// 是否上传文件,默认false,为true则默认使用FormData数据
isUpload?: boolean
// 传参数据,不区分method
data?: object
// 是否显示公共错误提示,默认true,为false可以在调用时捕获异常做处理
publicError?: boolean
// 请求发起前hook
requestHook?: (opts: AllType) => any
// 请求返回数据hook
responseHook?: (reslove: any, reject: any, data: any) => void
}
import { getGlobalAxios, getAxios, AllType, OptionsGlobalType } from '@dreamjser/request-axios'
import { showLoading, hideLoading } from './loading'
const globalOpts: OptionsGlobalType = {
timeout: 30000,
baseURL: GLOBAL_CONFIG.BASE_URL,
}
const axiosInstance = getGlobalAxios(globalOpts)
const requestHook = (config: AllType) => {
!config.slient && showLoading()
}
const responseHook = (reslove: any, reject: any, res: any) => {
const { config, data } = res
const { errorCode, errorMsg } = data
!config.slint && setTimeout(hideLoading, 100)
if (errorCode !== '0') {
if (config.publicError) {
App.interface.toast(errorMsg)
} else {
reject({
errorCode,
errorMsg,
})
}
return
}
reslove(data)
}
const request = (opts: AllType) => {
opts.requestHook = requestHook
opts.responseHook = responseHook
return getAxios(opts, axiosInstance).catch(() => {
App.interface.toast('网络请求失败')
})
}
export default request
FAQs
a request lib create by axios
The npm package @dreamjser/request-axios receives a total of 4 weekly downloads. As such, @dreamjser/request-axios popularity was classified as not popular.
We found that @dreamjser/request-axios demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.