Works together with Rails API
$ npm run start
Navigate to http://localhost:3000/:
(If you create it yourself)
$ npx create-react-app frontend-api
$ cd frontend-api/
$ yarn add http-proxy-middleware
const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function(app) {
app.use(
'/api',
createProxyMiddleware({
target: 'http://localhost:3001',
changeOrigin: true,
})
);
};
npm run start
Navigate to http://localhost:3000/:
*Don't forget to follow the instructions for the Rails API as well
*If you have similar "create-react-app is not working since version 4.0.1" problems, follow the instructions
Uninstall create-react-app v4.0.1:
# for npm:
npm uninstall -g create-react-app
# for yarn:
yarn global remove create-react-app
# for npm:
npm i create-react-app
# for yarn:
yarn add create-react-app
# for npx:
npx create-react-app my-app
# for npm:
npm init react-app my-app
# for yarn:
yarn create react-app my-app
*If it didn't solve the problem