Giter Site home page Giter Site logo

lei-mu / luch-request Goto Github PK

View Code? Open in Web Editor NEW
579.0 10.0 91.0 781 KB

luch-request 是一个基于Promise 开发的uni-app跨平台、项目级别的请求库,它有更小的体积,易用的api,方便简单的自定义能力。

Home Page: https://www.quanzhan.co/luch-request/

License: MIT License

JavaScript 89.70% Vue 6.51% SCSS 3.04% TypeScript 0.75%
luch-request dcloud promise-request uni uni-app promise request wechat github-stars

luch-request's People

Contributors

alwxkxk avatar hairyf avatar jessechain avatar lei-mu avatar modyqyw avatar zouyaoji avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

luch-request's Issues

开发环境接口能通,正式环境接口就不通

一样的请求地址,一样的代码,但是开发环境接口就能返回数据,但是一到体验版关闭调试或者线上版本,接口就不同了。这是为啥?用的是你文档中的 请求前拦截器的代码。我是在请求前给Header中添加token。

http.interceptors.request.use((config)=>{
    //... //业务代码,添加token
    return config;
}, config=>{
    // 经不断的调试后发现,就是这段代码有问题,把这段去掉,正式版里接口就能访问成功,
    // 但是如果是开发环境下,这段代码却不影响接口,是可以调通的。
    // 我看你的文档,use后面是两个handle,一个fulfilled,一个rejected,为什么在正式环境下,就不同了呢?
    return Promise.reject(config);
})

config 配置 dataType参数值

dataType 参数值只能是 json 吗? 还可以有其他哪些类型?

image

我主要是想解决: 后端接口返回订单号出现订单号精度丢失的情况。

dataType 默认是 json,执行了 JSON.parse()。导致 长数字类型精度丢失。

在 Axios 中会有个 transformResponse,可以解决这个问题,在 luch-request 中有没有这个东西?
参考文档: https://blog.51cto.com/u_15585699/5192081

image

希望增加并发请求的支持

后续版本可以增加像axios.all( )和axios.spread( )这样的并发请求吗?
例如车联网的车辆位置轨迹查询,数据量比较大,单次请求不太合适,用分页多次并发请求,成功后合并结果绘制轨迹。PC端我们采用这种方式实现,效果挺好。

在安卓6.0 webview 中加载uniapp h5网页,使用了该插件,报错。

我是一个用uniapp开发webapp的项目,在ios/android的webview中加载webapp。之前是直接下载源文件到代码里使用,没有问题。然后我看作者更新了,我就 用yarn加载使用,也没有问题。直到最近发现在oppo,红米的一些android 6.0版本的手机上,页面加载不出来。我用安卓调试,发现保错,unexpected token...
然后我一步步注释代码,发现import Request from "luch-request"有问题。然后我就试试下载源码,结果可以了,,,很奇怪。
刚开始我还以为是babel没有起作用,es6代码报错。
QQ拼音截图20201114105344
QQ拼音截图20201114105239

dataType设置无效

在这里 没有判断config.dataType 直接parse了
建议在这里加入对BigInt的支持

upload请求失败

xxx.vue
evaluateUploadPhoto({
filePath: this.imagesData[i],
name: 'photo',
header: {
'token': uni.getStorageSync('token')
}
})
index.js
export const evaluateUploadPhoto = params => (
http.upload('/evaluate/upload-photo', params)
)
mergeConfig.js插件里有去除content-type
// eslint-disable-next-line no-empty
if (method === 'DOWNLOAD') {

} else if (method === 'UPLOAD') {
config.method = 'POST'
delete config.header['content-type']
delete config.header['Content-Type']
const uploadKeys = [
// #ifdef APP-PLUS || H5
'files',
// #endif
// #ifdef MP-ALIPAY
'fileType',
// #endif
// #ifdef H5
'file',
// #endif
'filePath',
'name',
'formData',
]
uploadKeys.forEach(prop => {
if (typeof config2[prop] !== 'undefined') {
config[prop] = config2[prop]
}
})
}
但是请求头里还是包含了Content-Type
Request Headers
Connection: close
Content-Type: application/json
Date: Wed, 16 Dec 2020 06:34:12 GMT
Server: nginx/1.15.4
Transfer-Encoding: chunked

拦截器没调用


http.interceptors.response.use((response) => { /* 请求之后拦截器。可以使用async await 做异步操作  */
  // if (response.data.code !== 200) { // 服务端返回的状态码不等于200,则reject()
  //   return Promise.reject(response)
  // }
  console.log(response.data.code)
  if (response.data.code == 401) { // 服务端返回的状态码不等于200,则reject()
    uni.clearStorage()
	return Promise.reject(response)
  }
  return response
}, (response) => { // 请求错误做点什么。可以使用async await 做异步操作
  console.log(response)
  return Promise.reject(response)
})

export {
  http
}

版本3.0.7,401的时候没走进来

请问有木有设计删除拦截器的接口

目前luch-requrest 是支持创建多个实例和多个拦截器,导致现在的问题,当我在连续请求一个接口多次或者多个接口的时候,多个拦截器同触发,会造成性能内存的浪费,

请问怎样取消正在请求中的请求?

有一个场景是频繁请求同一个接口,假如前一次请求还没有完成响应,就取消前一次请求,因为假如前一次请求比当前这一次请求响应慢些的话,前一次的响应数据会覆盖当前请求的响应数据

同学,您这个项目引入了886个开源组件,存在24个漏洞,辛苦升级一下

检测到 lei-mu/luch-request 一共引入了886个开源组件,存在24个漏洞

漏洞标题:serialize-javascript 代码问题漏洞
缺陷组件:[email protected]
漏洞编号:CVE-2020-7660
漏洞描述:Verizon serialize-javascript是美国威瑞森电信(Verizon)公司的一款支持将JavaScript序列化为 JSON超集的软件包。
serialize-javascript 3.1.0之前版本中存在代码问题漏洞。远程攻击者可借助index.js文件中的‘deleteFunctions’函数利用该漏洞注入任意代码。
国家漏洞库信息:https://www.cnvd.org.cn/flaw/show/CNVD-2020-53801
影响范围:(∞, 3.1.0)
最小修复版本:3.1.0
缺陷组件引入路径:[email protected]>[email protected]>[email protected]
[email protected]>[email protected]>@vuepress/[email protected]>[email protected]>[email protected]
[email protected]>[email protected]>@vuepress/[email protected]>[email protected]>[email protected]>[email protected]
[email protected]>[email protected]>@vuepress/[email protected]>[email protected]>[email protected]

另外还有24个漏洞,详细报告:https://mofeisec.com/jr?p=i84d49

微信小程序真机调试错误

模拟器上没有问题 在真机调试就会出现这种错误 请问是因为是什么原因呢 用到了请求拦截和响应拦截

{errMsg: "request:fail -200:net::ERR_CERT_COMMON_NAME_INVALID", config: {…}}
errMsg: "request:fail -200:net::ERR_CERT_COMMON_NAME_INVALID"
config:
baseURL: "https://test.xxxx"
url: "/auth/token/wechat"
params: {}
custom: {}
header: {}
validateStatus: ƒ validateStatus(status)
data: {ob: Observer}
timeout: 30000
dataType: "json"
responseType: "text"

npm文档“常见问题”描述不准确

问题:在“为什么会请求两次?”的回答中,关于跨域的描述和介绍不够准确。
建议:详细阅读关于跨域的文章,最后修改“有两种可能,一种是‘post三次握手’”内容

请求出现”cant read property 'custom' of undefined“

请求的时候的时不时会提示“cant read property 'custom' of undefined”。这是什么原因导致的?代码如下:

`
//请求拦截器
http.interceptors.request.use((config) => { // 可使用async await 做异步操作
console.log('request interceptors')
console.log(config)
const token = getTokenStorage();
config.header = {
...config.header,
token: ''
}
if (token) {
config.header.token = 'Bearer ' + token;
}

if (config.method === 'POST') {
	config.data = JSON.stringify(config.data);
}

if (config.custom.loading) {
	uni.showLoading({title:'加载中...'})
}
return config

}, error => {
if (error.config.custom.loading) {
uni.hideLoading()
}
console.log('request interceptors error')
console.log(error)

console.log(error)
ret.code = (error.data==undefined||error.data.status==undefined)?405:error.data.status;
ret.message = (error.data==undefined||error.data.error==undefined)?error.errMsg:error.data.error;
return Promise.reject(error)

})
`

upload方法配置拦截器报错

`// request.js 拦截器封装
import Request from 'luch-request'
import {baseURL} from "@/config";

const service = new Request({
baseURL,
method: 'POST',
timeout: 12000 // request timeout
});

service.interceptors.request.use(
config => {
// 拦截器header加参
config.header = {
...config.header,
}
return config
},
error => {
return Promise.reject(error)
}
)

service.interceptors.response.use(
response => {
const res = response.data
if (res.returnCode !== 1) {
return Promise.reject(new Error(res.returnMsg || 'Error'))
}
return res
},
error => {
uni.showToast({
title: error.msg || 'Server Error',
icon: "none",
duration: 2 * 1000
})
return Promise.reject(error)
}
)
export default service`

// api.js import http from '../common/js/request' export const loginWeixin = ({code,encryptedData,iv})=>{ return http.request({ url: '/user/loginWeixin', data:{code,encryptedData,iv} }) } export const uploadFile = ({filePath})=>{ return http.upload('/file/uploadFile',{ name:'file', filePath, }) }
普通的request请求 loginWeixin没问题,但是uploadFile请求则直接进入响应拦截器的catch里面error了。。。

Uncaught Error: Module parse failed: Unexpected token (18:9) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See

const axios = require('luch-request')

const ins = new axios({
  baseUrl: config.baseURL
})

运行在小程序平台直接报错了, 请问大大这是为啥

Uncaught Error: Module parse failed: Unexpected token (18:9)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| 
| export default class Request {
>   config = {
|     baseUrl: '',
|     header: {},
    at Object.<anonymous> (luch-request.js:2)
    at __webpack_require__ (bootstrap:91)
    at Module.<anonymous> (luch-request.js:1)
    at __webpack_require__ (bootstrap:91)
    at Object.<anonymous> (req.ts:2)
    at __webpack_require__ (bootstrap:91)
    at Object.<anonymous> (v1.ts:1)
    at __webpack_require__ (bootstrap:91)
    at Object.<anonymous> (index.vue?e69b:29)
    at __webpack_require__ (bootstrap:91)

关于请求错误重连的问题

老哥 请问 如果发送一个请求A 此时A请求报错了 进入了响应错误拦截器回调 在这个回调中如何去重新再次发起前一次请求,并且成功后能在A请求的.then(success=>{})中进行触发。
现在遇到的问题是 只要请求报错进入拦截器 就会触发 A请求.then(success=>{},error=>{})中的error回调
就算我返回的是promise依然会进入error 无法进行多次请求重试的效果
响应错误拦截器回调中的代码

const backoff = new Promise(function(resolve){
        setTimeout(()=>{
            resolve()
        },config.custom.retryDelay || 16)
    })
    return backoff.then(()=>{
        return instance.request(config)
       //此处instance.request(config).then(succes=>{})会触发数据回调 但是怎么把数据回调给到页面中的请求呢?
    })

请问有木有设计删除控制器的接口

目前luch-requrest 是支持创建多个实例和多个拦截器,导致现在的问题,当我在连续请求一个接口多次或者多个接口的时候,多个拦截器同触发,会造成性能内存的浪费,

请指教,关于file文件上传问题

已知文档处写明:data支持的文件类型只有Object/String/ArrayBuffer</code>这个真跟我没啥关系 0.0

场景需求:

上传多图片file[]后端这样子接收,一般都会这么操作哇,先说一般情况下~(且携带其他信息,一同formData提交)

操作 :(H5端下测试)

尝试使用post请求,JSON对象作为data参数,设置header Content-type: ''application/x-www-form-urlencoded; charset=UTF-8"
成功上传格式 FormData,

问题:

  • file无法无法实现多个 file[]...
  • file 变成 [obejct File], [obejct File] ... (应该是(binary) 才是的捏)

请问作者,如何去实现可上传FormData参数呢?(这个问题我看下源码,不知道是从那部开始做转换的呢)
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.