当前位置:网站首页>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
边栏推荐
- PC uses wireless network card to connect to mobile phone hotspot. Why can't you surf the Internet
- 209. Minimum length subarray - sliding window
- 【Appium】通过设计关键字驱动文件来编写脚本
- ECMAScript history
- Using quartz under. Net core -- general properties and priority of triggers for [5] jobs and triggers
- 01 - get to know the advantages of sketch sketch
- Flash project cross domain interception and DBM database learning [Baotou cultural and creative website development]
- Compare the performance of query based on the number of paging data that meet the query conditions
- 102. 二叉树的层序遍历
- The system cannot be started after AHCI is enabled
猜你喜欢

440. The k-th small number of dictionary order (difficult) - dictionary tree - number node - byte skipping high-frequency question

Allowed latency and side output

JVM class loading mechanism

01-初识sketch-sketch优势

Hcip fifth experiment

Kubernetes service discovery monitoring endpoints

双闭环直流调速系统matlab/simulink仿真

干货 | 快速抽取缩略图是怎么练成的?
![Using quartz under. Net core -- job attributes and exceptions of [4] jobs and triggers](/img/ec/43dddd18f0ce215f0f1a781e31f6a8.png)
Using quartz under. Net core -- job attributes and exceptions of [4] jobs and triggers
![Using quartz under. Net core - [1] quick start](/img/80/b99417e88d544ca6e3da4c0c1625ce.png)
Using quartz under. Net core - [1] quick start
随机推荐
Clickhouse SQL operation
JS parsing and execution process
440. The k-th small number of dictionary order (difficult) - dictionary tree - number node - byte skipping high-frequency question
关于gcc输出typeid完整名的方法
For the space occupation of the software, please refer to the installation directory
Understanding of RPC core concepts
31. Next arrangement
Websocket (basic)
Advantages and disadvantages of several note taking software
Index: teach you index from zero basis to proficient use
圆环回原点问题-字节跳动高频题
Perception of linear algebra 2
Generating access keys using JSON webtoken
1217_使用SCons生成目标文件
Kubernetes 服务发现 监控Endpoints
Understanding and small examples of unity3d object pool
In ancient Egypt and Greece, what base system was used in mathematics
Kubernetes service discovery monitoring endpoints
SystemVerilog(六)-变量
HCIP第五次实验