react 代理端口,修改localhost端口

1. 在package.josn修改, 添加proxy

{
  "name": "my-new-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "axios": "^0.18.0",
    "fs": "^0.0.1-security",
    "hoist-non-react-statics": "^3.0.1",
    "multiparty": "^4.2.1",
    "mysql": "^2.16.0",
    "react": "^16.4.2",
    "react-dom": "^16.4.2",
    "react-router": "^4.3.1",
    "react-router-dom": "^4.3.1",
    "react-scripts": "1.1.5"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "proxy": {
    "/api": {
      "target": "http://localhost:3000",
      "secure": "false",
      "changeOrigin": "true",
      "pathRewrite": {
        "^/api": ""
      }
    }
  }
}

2. 修改react localhost端口:node_modules\react-scripts\scripts\start.js,在npm start

posted @ 2018-08-24 16:57  LWJ_jay  阅读(3005)  评论(0编辑  收藏  举报