问题描述
我正尝试关注文档并创建了vite.config.js
,如下所示:
const config = {
outDir: '../wwwroot/',proxy: {
// string shorthand
'/foo': 'http://localhost:4567',// with options
'/api': {
target: 'http://jsonplaceholder.typicode.com',changeOrigin: true,rewrite: path => path.replace(/^\/api/,'')
}
}
};
export default config;
并尝试通过以下调用对其进行测试:
fetch('/foo');
fetch('/api/test/get');
我希望收到的实际请求为http://localhost:4567/foo
和http://jsonplaceholder.typicode.com/test/get
但是他们两个都将我的开发服务器作为这样的来源:http://localhost:3000/foo
和http://localhost:3000/api/test/get
我误会了吗?代理应该如何工作?
我还在Vite仓库中创建了一个issue,但是它已关闭,我听不懂结束语。
解决方法
原来需要将secure
标志指定为false,如下所示:
proxy: {
'/api': {
target: 'https://localhost:44305',changeOrigin: true,secure: false,ws: true,}
}
相关的github issue