jli*_*eza 5 proxy create-react-app vite
在create-react-app我可以添加一个属性package.json:
"proxy": "https://some.server.com"
每次执行请求时fetch,每个调用(无论路径如何)都会代理到指定的目标。
实际上,我能做的最好的事情就是这样:
export default defineConfig({
server: {
proxy: {
'/api': {
target: 'https://some.server.com',
changeOrigin: true,
secure: false,
},
}
}
})
Run Code Online (Sandbox Code Playgroud)
它有效,但我需要明确指定路径。例如,如果我需要代理不以 开头的获取请求/api,我需要将其重写为^/(api|something-else)': {...}
如何让它以与 中相同的方式工作create-react-app,这样我就不必显式指定代理路径,并且只代理提取请求?
| 归档时间: |
|
| 查看次数: |
749 次 |
| 最近记录: |