- you should be using
fetch('/cregister/api/customer/list')(don't include the protocol/host/port) - for your react development server (the thing running on port 3000), you should configure a proxy to redirect all API requests to port 3001
- you should not be using a react development server in production. for production, you "build" your react app and let the server running on port 3001 serve the built files.
#React connect to API Rest
11 messages · Page 1 of 1 (latest)
Thanks , i implemented setupProxy.js
const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function (app) {
app.use(
'/cregister',
createProxyMiddleware({
target: 'http://localhost:3001',
changeOrigin: true,
})
);
};
About "you should not be using a react development server in production. for production, you "build" your react app and let the server running on port 3001 serve the built files."
Sorry, I don't get it.
Actually i use npm run build and npm start for my app.
So what i should do to get my app working with API Rest ?
Are you using CRA?
i used npm install with tsconfig.json and package.json files
...
if you're using your own custom framework and/or build system, glhf... if you're using CRA, Vite, or something somebody else has used, somebody can probably help.
what part of what I said do you not understand? do you get what is happening when you type npm run start or npm run build?
I followed a course thats why i did like this.
I will rewrite my app by using CRA.
Vite is preferred these days
Thanks for your advice so i will take a look to it. 👍🏻