create-react-app设置proxy反向代理不起作用
在CRA2.X升级以后对proxy的设置做了修改,引用官方升级文档:
Object
proxyconfiguration is superseded bysrc/setupProxy.jsTo check if action is required, look for the
proxykey inpackage.jsonand follow this table:
- I couldn't find a
proxykey inpackage.json
- No action is required!
- The value of
proxyis a string (e.g.http://localhost:5000)
- No action is required!
- The value of
proxyis an object
- Follow the migration instructions below.
It's worth highlighting: if your
proxyfield is astring, e.g.http://localhost:5000, or you don't have it, skip this section. This feature is still supported and has the same behavior.If your
proxyis 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": "http://localhost:5000/"
},
"/*.svg": {
"target": "http://localhost:5000/"
}
}
迁移到setupProxy.js中
const proxy = require('http-proxy-middleware');
module.exports = function(app) {
app.use(proxy('/api', { target: 'http://localhost:5000/' }));
app.use(proxy('/*.svg', { target: 'http://localhost:5000/' }));
};
create-react-app设置proxy反向代理不起作用的更多相关文章
- 深入 Create React App 核心概念
本文差点难产而死.因为总结的过程中,多次怀疑本文是对官方文档的直接翻译和简单诺列:同时官方文档很全面,全范围的介绍无疑加深了写作的心智负担.但在最终的梳理中,发现走出了一条与众不同的路,于是坚持分享出 ...
- 使用create react app教程
This project was bootstrapped with Create React App. Below you will find some information on how to ...
- 在 .NET Core 5 中集成 Create React app
翻译自 Camilo Reyes 2021年2月22日的文章 <Integrate Create React app with .NET Core 5> [1] Camilo Reyes ...
- Nginx设置Https反向代理,指向Docker Gitlab11.3.9 Https服务
目录 目录 1.GitLab11.3.9的安装 2.域名在阿里云托管,申请免费的1年证书 3.Gitlab 的 https 配置 4.Nginx 配置 https,反向代理指向 Gitlab 配置 目 ...
- tap news:week5 0.0 create react app
参考https://blog.csdn.net/qtfying/article/details/78665664 先创建文件夹 安装create react app 这个脚手架(facebook官方提 ...
- 如何扩展 Create React App 的 Webpack 配置
如何扩展 Create React App 的 Webpack 配置 原文地址https://zhaozhiming.github.io/blog/2018/01/08/create-react-a ...
- Docker Nginx-Proxy 容器Nginx Proxy反向代理
Docker Nginx-Proxy 容器Nginx Proxy反向代理 简单介绍 Docker容器的自动Nginx反向代理 dockerhub地址 https://hub.docker.co ...
- app与jvm 反向代理时config的设置(用于在web页面显示npm(就如tomcat)产生的页面)
dev: { // Various Dev Server settings contentBase: ROOT, host: ip, port: 8084, //此端口为任意设置,不重复即可,为 ...
- Create React App
Facebook开源了React前端框架(MIT Licence),也同时提供了React脚手架 - create-react-app. create-react-app遵循约定优于配置(Coc)的原 ...
随机推荐
- dxjk中 支付宝二维码支付 git 存疑
线上的vendor/latrell/alipay 文件拉取不了至本地,失去了git监控 要想本地使用 1.注释掉config/app.php 'providers' 下的Latrell模块 2.下载线 ...
- spring bean id重复覆盖的问题解决
问题: 当我们的web应用做成一个大项目之后,里面有很多的bean配置,如果两个bean的配置id是一样的而且实现类也是一样的,例如有下面两份xml的配置文档: beancontext1.xml &l ...
- 表空间 -- tablespace
表空间是数据库的逻辑划分,一个表空间只能属于一个数据库.所有的数据库对象都存放在指定的表空间中.但主要存放的是表, 所以称作表空间. Oracle数据库中至少存在一个表空间,即SYSTEM的表空间. ...
- org/apache/hadoop/hbase/mapreduce/TableReducer:Unsupported major.minor version52.0
问题详情: 问题原因: <dependency> <groupId>org.apache.hbase</groupId> <artifactId& ...
- window.open()打开新窗口被拦截
window.open( url )是常用的打开新页面的方法,一般都没有问题,但是如果在ajax回调方法里面使用就会被浏览器拦截,因为在浏览器安全机制中,页面弹窗必须是由用户触发的才是安全弹窗,比如说 ...
- 进程句柄和进程ID的区别和关系
进程和进程句柄和进程id含义 进程是一个正在运行的程序,进程里可以包括多个模块(DLL,OCX,等)进程句柄是程序访问时用到的东西,当前进程句柄等于主模块的句柄,当你使用OpenProcess时的进程 ...
- javascript中的类方法、构造方法、原型方法的对比
如果你已经接触js很久了,那么应该可以看看我总结的是否正确,如果你刚开始学习,那么通过我的总结,你可以更快的区别他们,记得我刚接触js时,这一块反正是模糊了很久! 1,长相的区别: function ...
- Android 4 学习(11):Intent简介
参考<Professional Android 4 Development> Intents 本文主要从这几个方面介绍Intents: 使用Intents在Android程序内部或外部通信 ...
- Halcon学习(八)文本操作
标签: 学习 杂谈 分类: halcon学习 1.open_file( : : FileName, FileType : FileHandle) FileType: 'output':创建文本 ‘ap ...
- EXT.net 窗体传值
ext.net 窗体传值 EXT.net 窗体传值 子窗体代码 protected void btnClose_Click(object sender,EventArges e) { PageCont ...