当前位置:网站首页>Vite configure proxy proxy to solve cross domain
Vite configure proxy proxy to solve cross domain
2022-04-23 17:46:00 【Suk_ A Shuo】
Code up :
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, // Strict port true: If the port is already in use , You just quit , Instead of trying on subsequent ports .
/**
* @description solve chrome Set up origin:* Also cross domain mechanisms , agent /api Prefix to service base address
* The final address will be axios Set up baseUrl:/api The agent is spliced into [target][/api], And then through rewrite Rewrite it /api by '' This is our real base site
*/
proxy: {
'/api': {
target: 'http://www.baidu.com', // Interface address base
rewrite: path => {
console.log(path); // Print [/api/userInfo] This is it. http-proxy Requesting url, Our base address is actually not available /api therefore replace fall
return path.replace(/^\/api/, '');
}
}
}
},
plugins: [vue()],
resolve: {
alias: {
'@': resolve(__dirname, '.', 'src') // Set up @ Point to src
}
},
})
版权声明
本文为[Suk_ A Shuo]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231741180609.html
边栏推荐
- PC电脑使用无线网卡连接上手机热点,为什么不能上网
- Use of todesk remote control software
- ros常用的函数——ros::ok(),ros::Rate,ros::spin()和ros::spinOnce()
- In ancient Egypt and Greece, what base system was used in mathematics
- [二叉数] 二叉树的最大深度+N叉树的最大深度
- MySQL advanced index [classification, performance analysis, use, design principles]
- On the method of outputting the complete name of typeID from GCC
- Commonly used functions -- spineros:: and spineros::)
- 209. 长度最小的子数组-滑动窗口
- The JS timestamp of wechat applet is converted to / 1000 seconds. After six hours and one day, this Friday option calculates the time
猜你喜欢
编译原理 求first集 follow集 select集预测分析表 判断符号串是否符合文法定义(有源码!!!)
470. Rand10() is implemented with rand7()
48. Rotate image
为什么有些人说单片机简单,我学起来这么吃力?
Land cover / use data product download
Client example analysis of easymodbustcp
Why do some people say SCM is simple and I have to learn it so hard?
Future 用法详解
SystemVerilog (VI) - variable
SystemVerilog(六)-变量
随机推荐
常用SQL语句总结
2022年流动式起重机司机国家题库模拟考试平台操作
MySQL进阶之索引【分类,性能分析,使用,设计原则】
Hcip fifth experiment
Qt error: /usr/bin/ld: cannot find -lGL: No such file or directory
QT modification UI does not take effect
Commonly used functions -- spineros:: and spineros::)
高德地图搜索、拖拽 查询地址
Applet learning notes (I)
[appium] write scripts by designing Keyword Driven files
In JS, t, = > Analysis of
练习:求偶数和、阈值分割和求差( list 对象的两个基础小题)
JS implementation private attribute
Uniapp custom search box adaptation applet alignment capsule
394. 字符串解码-辅助栈
Chrome浏览器的跨域设置----包含新老版本两种设置
Use of todesk remote control software
Element calculation distance and event object
The method of changing a value in the array and a value in the object of wechat applet
SystemVerilog (VI) - variable