当前位置:网站首页>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
边栏推荐
猜你喜欢
HCIP第五次实验
Allowed latency and side output
Error in created hook: "referenceerror:" promise "undefined“
Exercise: even sum, threshold segmentation and difference (two basic questions of list object)
958. 二叉树的完全性检验
Kubernetes service discovery monitoring endpoints
Future usage details
958. Complete binary tree test
Applet learning notes (I)
Hcip fifth experiment
随机推荐
Metaprogramming, proxy and reflection
练习:求偶数和、阈值分割和求差( list 对象的两个基础小题)
31. 下一个排列
Compare the performance of query based on the number of paging data that meet the query conditions
干货 | 快速抽取缩略图是怎么练成的?
Indexes and views in MySQL
vite配置proxy代理解决跨域
ES6 new method
Error in created hook: "referenceerror:" promise "undefined“
How to manually implement the mechanism of triggering garbage collection in node
394. String decoding - auxiliary stack
Exercise: even sum, threshold segmentation and difference (two basic questions of list object)
圆环回原点问题-字节跳动高频题
MySQL进阶学习之SQL优化【插入,主键,排序,分组,分页,计数】
剑指 Offer 03. 数组中重复的数字
Some questions some questions some questions some questions
Sword finger offer 03 Duplicate number in array
209. 长度最小的子数组-滑动窗口
Construction of functions in C language programming
JVM类加载机制