在CRA2.X升级以后对proxy的设置做了修改,引用官方升级文档:

Object proxy configuration is superseded by src/setupProxy.js

To check if action is required, look for the proxy key in package.json and follow this table:

  1. I couldn't find a proxy key in package.json

    • No action is required!
  2. The value of proxy is a string (e.g. http://localhost:5000)
    • No action is required!
  3. The value of proxy is an object
    • Follow the migration instructions below.

It's worth highlighting: if your proxy field is a string, 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 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": "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反向代理不起作用的更多相关文章

  1. 深入 Create React App 核心概念

    本文差点难产而死.因为总结的过程中,多次怀疑本文是对官方文档的直接翻译和简单诺列:同时官方文档很全面,全范围的介绍无疑加深了写作的心智负担.但在最终的梳理中,发现走出了一条与众不同的路,于是坚持分享出 ...

  2. 使用create react app教程

    This project was bootstrapped with Create React App. Below you will find some information on how to ...

  3. 在 .NET Core 5 中集成 Create React app

    翻译自 Camilo Reyes 2021年2月22日的文章 <Integrate Create React app with .NET Core 5> [1] Camilo Reyes ...

  4. Nginx设置Https反向代理,指向Docker Gitlab11.3.9 Https服务

    目录 目录 1.GitLab11.3.9的安装 2.域名在阿里云托管,申请免费的1年证书 3.Gitlab 的 https 配置 4.Nginx 配置 https,反向代理指向 Gitlab 配置 目 ...

  5. tap news:week5 0.0 create react app

    参考https://blog.csdn.net/qtfying/article/details/78665664 先创建文件夹 安装create react app 这个脚手架(facebook官方提 ...

  6. 如何扩展 Create React App 的 Webpack 配置

    如何扩展 Create React App 的 Webpack 配置  原文地址https://zhaozhiming.github.io/blog/2018/01/08/create-react-a ...

  7. Docker Nginx-Proxy 容器Nginx Proxy反向代理

    Docker Nginx-Proxy 容器Nginx Proxy反向代理   简单介绍 Docker容器的自动Nginx反向代理   dockerhub地址 https://hub.docker.co ...

  8. app与jvm 反向代理时config的设置(用于在web页面显示npm(就如tomcat)产生的页面)

    dev: { // Various Dev Server settings contentBase: ROOT, host: ip, port: 8084,    //此端口为任意设置,不重复即可,为 ...

  9. Create React App

    Facebook开源了React前端框架(MIT Licence),也同时提供了React脚手架 - create-react-app. create-react-app遵循约定优于配置(Coc)的原 ...

随机推荐

  1. C#去除数组空格

    static void Main(string[] args) { "}; Console.WriteLine("输出带有空字符串的数组:"); foreach (str ...

  2. cors,跨域资源共享,Java配置

    一.概念 1. 如果两个页面的协议.域名和端口是完全相同的,那么它们就是同源的,不同则为跨域 2. ajax本身实际上是通过XMLHttpRequest对象来进行数据的交互,而浏览器出于安全考虑,不允 ...

  3. verilog 建模笔记--低级建模

    来源  <verilog HDL那些事--建模篇> 1.并行建模的思想. 2.每个模块最好只有一个功能.(便于修改和扩展,特别在大的项目中) 典型的 HDL 教科书中,才不会要读者了解“模 ...

  4. DVWA平台v1.8-SQL注入(low级别)

    代码 <?php if(isset($_GET['Submit'])){ // Retrieve data $id = $_GET['id']; $getid = "SELECT fi ...

  5. div+css显示两行或三行文字

    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: ; //需要控制的文本行数 overflow: hidd ...

  6. 第一次接触python:学习最简单的print及变量

    # -*- coding:utf-8 -*- print "hello world" print("hello world") 这里面使用了2中print方式, ...

  7. Net Framework 4.0 和.Net Framework 4.0 Client Profile

    Net Framework 4.0 和.Net Framework 4.0 Client Profile区别: .Net Framework 4.0毫无疑问就像是.Net Framework 2.0一 ...

  8. ffmpeg-URL(转)

    ffmpeg中为方便对资源进行访问,定义了两个结构体,URLContext中是对具体资源文件进行操作的上下文,URLProtocol则是在将资源进行分类的基础上,对某一类资源操作的函数集,熟悉Linu ...

  9. scala 在vim中的语法高亮

    https://github.com/derekwyatt/vim-scala 提供了一个选择 看install手册,发现两个命令都是必须的. mkdir -p ~/.vim/{ftdetect,in ...

  10. 爬虫模块之Request

    requests Requests唯一一个非转基因的Python HTTP库,人类就可以安全享用. Python标准库中提供了:urllib.urllib2.httplib等模块以供Http请求,但是 ...