当前位置:网站首页>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
边栏推荐
- Open futures, open an account, cloud security or trust the software of futures companies?
- MySQL进阶之索引【分类,性能分析,使用,设计原则】
- 练习:求偶数和、阈值分割和求差( list 对象的两个基础小题)
- 剑指 Offer 22. 链表中倒数第k个节点-快慢指针
- Index: teach you index from zero basis to proficient use
- Manually implement simple promise and its basic functions
- 1217_使用SCons生成目标文件
- tidb-server 的配置文件在哪里?
- Using quartz under. Net core -- a simple trigger of [7] operation and trigger
- Clickhouse table engine
猜你喜欢
EasymodbusTCP之clientexample解析
Future usage details
XTask与Kotlin Coroutine的使用对比
102. 二叉树的层序遍历
Summary of common SQL statements
SQL optimization for advanced learning of MySQL [insert, primary key, sort, group, page, count]
索引:手把手教你索引从零基础到精通使用
92. Reverse linked list II byte skipping high frequency question
Qt error: /usr/bin/ld: cannot find -lGL: No such file or directory
uni-app黑马优购项目学习记录(下)
随机推荐
Excel quickly and automatically fills the contents of a row on a blank cell
122. The best time to buy and sell stocks II - one-time traversal
Kubernetes service discovery monitoring endpoints
Perception of linear algebra 2
48. 旋转图像
Websocket (basic)
Halo open source project learning (II): entity classes and data tables
Some questions some questions some questions some questions
[simple understanding of database]
SQL optimization for advanced learning of MySQL [insert, primary key, sort, group, page, count]
394. String decoding - auxiliary stack
01-初识sketch-sketch优势
Change Oracle to MySQL
MySQL advanced index [classification, performance analysis, use, design principles]
[logical fallacy in life] Scarecrow fallacy and inability to refute are not proof
[batch change MySQL table and corresponding codes of fields in the table]
How to manually implement the mechanism of triggering garbage collection in node
Index: teach you index from zero basis to proficient use
古代埃及希腊,数学用的什么进制
Commonly used functions -- spineros:: and spineros::)