当前位置: 首页 > news >正文

在vue3的vite网络请求报错 [vite] http proxy error:

在开发的过程中 代理proxy报错:

[vite] http proxy error: /ranking/hostRank?dateType=1
Error: connect ETIMEDOUT 43.xxx.xxx.xxx:443

网络请求是http的:

// vite.config.ts
import { Agent } from 'node:http';server: {host: '0.0.0.0',port: port,open: true,https: false,proxy: {'***': {target: '***',ws: true,changeOrigin: true,agent: new Agent({ keepAlive: true, keepAliveMsecs: 20000 }), // add this line},},},

网络请求是https的:

// vite.config.ts
import { Agent } from 'node:https';server: {host: '0.0.0.0',port: port,open: true,https: false,proxy: {'***': {target: '***',ws: true,changeOrigin: true,agent: new Agent({ keepAlive: true, keepAliveMsecs: 20000 }), // add this line},},},

上面本人亲测有效

提示:如果是使用yarn

yarn add agent-base
yarn add http

import http from "http";
agent: new http.Agent({keepAlive: true, keepAliveMsecs: 20000})

如果代理地址是localhost

不用localhost,将proxy配置中的target的地址改成使用127.0.0.1 (其他人已谈到的解决方案)

另外还有大佬提到下面这个,提供参考

export NODE_OPTIONS="--dns-result-order=ipv4first"
vite

http://www.lryc.cn/news/481120.html

相关文章:

  • ElasticSearch 简单的查询。查询存在该字段的资源,更新,统计
  • FOFA使用教程之从零到精通
  • 【提高篇】3.2 GPIO(二,基本结构)
  • UE hard/soft reference| DDX DDY | Unity pcg color
  • macOS 应用公证指南:使用 fastlane 实现自动化公证流程
  • 深度学习:解密图像、音频和视频数据的“理解”之道20241105
  • uniapp 实现瀑布流
  • 计算机毕业设计 | springboot+vue智慧工地管理系统 前后端分离后台管理(附源码+文档)
  • vue中html如何转成pdf下载,pdf转base64,忽略某个元素渲染在pdf中,方法封装
  • Ubuntu下如何管理多个ssh密钥
  • [vulnhub] DarkHole: 1
  • 商淘云连锁企业管理五大功能 收银系统助力门店进销存同步
  • 统信UOS开发环境支持Perl
  • Stable Diffusion Web UI - ControlNet 姿势控制 openpose
  • java中Json字符串转换
  • springboot处理跨域请求
  • S32G-VNP-RDB2开发环境搭建
  • 分布式唯一ID生成(二): leaf
  • 【开发工具】Git
  • 【go从零单排】结构嵌套struct embedding
  • Django 详细入门介绍
  • 万字长文解读深度学习——循环神经网络RNN、LSTM、GRU、Bi-RNN
  • HDR视频技术之二:光电转换与 HDR 图像显示
  • 【Linux】Linux入门实操——vim、目录结构、远程登录、重启注销
  • Redis的缓存问题与应对策略
  • Java项目实战II基于Spring Boot的智慧生活商城系统的设计与实现(开发文档+数据库+源码)
  • 每日一题之成绩排序
  • QT Widget:使用技巧
  • 深入Zookeeper节点操作:高级功能与最佳实践
  • 【C++】map和set的介绍及使用