我在安装http-proxy-middleware之后在src目录中创建了setupProxy.js文件,
const proxy = require('http-proxy-middleware');
module.exports = function(app) {
app.use(proxy('/api/', { target: 'http://localhost:3002' }));
};
这是我的App.js文件
import React, { Component } from 'react';
import axios from 'axios';
import './App.css';
class App extends Component {
componentDidMount(){
axios.get('/api/product/brands').then(response => {
console.log(response);
});
}
render() {
return (
<div className="App">
<p>Store!</p>
</div>
);
}
};
export default App;
我在服务器目录package.json文件中执行了此操作,以同时运行客户端和服务器
"start": "node server/server.js",
"server": "nodemon server/server.js",
"client": "npm run start --prefix client",
"dev":"concurrently \"npm run server\" \"npm run client\""
当我遇到404错误时,请帮助我