在CRA2.X升级以后对proxy的设置做了修改,引用官方升级文档:
Object
proxy
configuration is superseded bysrc/setupProxy.js
To check if action is required, look for the
proxy
key inpackage.json
and follow this table:
- I couldn't find a
proxy
key inpackage.json
- No action is required!
- The value of
proxy
is a string (e.g.localhost:5000
)
- No action is required!
- The value of
proxy
is an object
- Follow the migration instructions below.
It's worth highlighting: if your
proxy
field is astring
, e.g.localhost:5000
, or you don't have it, skip this section. This feature is still supported and has the same behavior.If your
proxy
is an object, that means you are using the advanced proxy configuration. It has become fully customizable so we removed the limited support for the object-style configuration. Here's how to recreate it.
如果proxy的值是字符串,不需要修改
如果proxy的值是一个json,则需要做如下修改:
1. npm install http-proxy-middleware
2. src文件夹根目录下创建 setupProxy.js 文件
3. package.json中的
"proxy": {"/api": {"target": "localhost:5000/"},"/*.svg": {"target": "localhost:5000/"} }
迁移到setupProxy.js中
const proxy = require('http-proxy-middleware');ports = function(app) {app.use(proxy('/api', { target: 'localhost:5000/' }));app.use(proxy('/*.svg', { target: 'localhost:5000/' })); };
转载于:.html
本文发布于:2024-02-04 19:42:22,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170715023358935.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |