create-react-app之proxy

react

create-react-app之proxy】

  create-react-app可以用于一键创建web_client环境,默认使用webpack-dev-server。但在开发过程中,往往需要client/server配合调试。当我们需要将请求发送到自有服务器而非webpack-dev-server时,怎么办呢?

  To tell the development server to proxy any unknown requests to your API server in development, add a proxy field to your package.json, for example:

  

  "proxy": "http://localhost:4000",

  This way, when you fetch('/api/todos') in development, the development server will recognize that it’s not a static asset, and will proxy your request to http://localhost:4000/api/todos as a fallback. The development server will only attempt to send requests without a text/html accept header to the proxy.

  

参考:https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#proxying-api-requests-in-development

以上是 create-react-app之proxy 的全部内容, 来源链接: utcz.com/z/382533.html

回到顶部