当前位置:网站首页>vite配置proxy代理解决跨域
vite配置proxy代理解决跨域
2022-04-23 17:41:00 【Suk_阿硕】
上代码:
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { resolve } from 'path';
// https://vitejs.dev/config/
export default defineConfig({
server: {
port: 9090,
strictPort: true, // 严格端口 true:如果端口已被使用,则直接退出,而不会再进行后续端口的尝试。
/**
* @description 解决chrome设置origin:*也跨域机制,代理/api前缀到服务基地址
* 最终的地址会将axios设置的baseUrl:/api代理拼接成[target][/api],然后通过rewrite重写掉/api为'' 这样就是我们真实的基地址了
*/
proxy: {
'/api': {
target: 'http://www.baidu.com', // 接口基地址
rewrite: path => {
console.log(path); // 打印[/api/userInfo] 这就是http-proxy要请求的url,我们基地址实际是没有/api 所以replace掉
return path.replace(/^\/api/, '');
}
}
}
},
plugins: [vue()],
resolve: {
alias: {
'@': resolve(__dirname, '.', 'src') // 设置 @ 指向 src
}
},
})
版权声明
本文为[Suk_阿硕]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Suk__/article/details/124310263
边栏推荐
- 958. 二叉树的完全性检验
- Kubernetes service discovery monitoring endpoints
- 41. 缺失的第一个正数
- 双指针进阶--leetcode题目--盛最多水的容器
- Ring back to origin problem - byte jumping high frequency problem
- [simple understanding of database]
- Understanding and small examples of unity3d object pool
- How to sort the numbers with text in Excel from small to large instead of the first number
- 练习:求偶数和、阈值分割和求差( list 对象的两个基础小题)
- Exercise: even sum, threshold segmentation and difference (two basic questions of list object)
猜你喜欢
394. 字符串解码-辅助栈
Clickhouse table engine
01 - get to know the advantages of sketch sketch
Using quartz under. Net core -- general properties and priority of triggers for [5] jobs and triggers
In embedded system, must the program code in flash be moved to ram to run?
Understanding of RPC core concepts
Halo 开源项目学习(二):实体类与数据表
2. Electron's HelloWorld
394. String decoding - auxiliary stack
MySQL进阶之索引【分类,性能分析,使用,设计原则】
随机推荐
Metaprogramming, proxy and reflection
209. Minimum length subarray - sliding window
Manually implement call, apply and bind functions
QT modification UI does not take effect
2021 Great Wall Cup WP
Kubernetes service discovery monitoring endpoints
Come out after a thousand calls
Using quartz under. Net core -- general properties and priority of triggers for [5] jobs and triggers
Dry goods | how to extract thumbnails quickly?
Where is the configuration file of tidb server?
Open futures, open an account, cloud security or trust the software of futures companies?
Low code development platform sorting
122. The best time to buy and sell stocks II - one-time traversal
Future 用法详解
Perception of linear algebra 2
ros常用的函数——ros::ok(),ros::Rate,ros::spin()和ros::spinOnce()
31. 下一个排列
440. The k-th small number of dictionary order (difficult) - dictionary tree - number node - byte skipping high-frequency question
C语言程序设计之函数的构造
Some questions some questions some questions some questions