鍍金池/ 問答/HTML5  HTML/ create react app構(gòu)建, build之后接口報404?

create react app構(gòu)建, build之后接口報404?

1.我使用的搭建環(huán)境是 create react app,想做的事情是請求豆瓣api,但是因?yàn)榭缬?,配置了proxy,并且為了部署到github page上,package.json也配置了相應(yīng)的homepage.
本地運(yùn)行時候沒有問題,但是build部署到線上就報錯:

Failed to load resource: the server responded with a status of 404 ()

我的package.json:

{
  "name": "imovie",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.4.2",
    "react-dom": "^16.4.2",
    "react-scripts": "1.1.4",
    "antd-mobile": "^2.2.2"
  },
  "scripts": {
    "start": "react-app-rewired start",
    "build": "react-app-rewired build",
    "test": "react-app-rewired test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "devDependencies": {
    "axios": "^0.18.0",
    "babel-plugin-import": "^1.8.0",
    "css-loader": "^1.0.0",
    "less": "^3.8.1",
    "less-loader": "^4.1.0",
    "qs": "^6.5.2",
    "react-app-rewired": "^1.5.2",
    "style-loader": "^0.22.0"
  },
  "proxy": "https://api.douban.com",
  "homepage": "https://lawlietze.github.io/testServer"
}

我的請求部分:

    componentDidMount(){
        let _This = this;
        axios.get('/v2/movie/in_theaters')
        .then(function (response) {
            console.log(response);
            _This.setState({ result: response.data.subjects });
        })
        .catch(function (error) {
        console.log(error);
        });
    }

問題出現(xiàn)的環(huán)境背景及自己嘗試過哪些方法

相關(guān)代碼

// 請把代碼文本粘貼到下方(請勿用圖片代替代碼)

你期待的結(jié)果是什么?實(shí)際看到的錯誤信息又是什么?

回答
編輯回答
亮瞎她

你看一下控制臺有沒有請求到真的豆瓣的接口不就好了嘛

2018年4月29日 22:20
編輯回答
深記你

開發(fā)的時候配置了proxy可以代理,打包后也需要配置proxy代理,比如使用nginx

2018年6月19日 07:08