/React_API_wRails_API

React Frontend API for Backend Rails API. Using CRUD as an example

Primary LanguageJavaScript

Interaction of two APIs React-Rails, Frontend-Backend

Works together with Rails API

Clone the repository, run

$ npm run start

Set up the App*

(If you create it yourself)

$ npx create-react-app frontend-api

$ cd frontend-api/

$ yarn add http-proxy-middleware

In /src, create a file called setupProxy.js

const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function(app) {
    app.use(
        '/api',
        createProxyMiddleware({
            target: 'http://localhost:3001',
            changeOrigin: true,
        })
    );
};
npm run start

*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