First of all I say that I know how to make it work but don't understand how .
in my React there's some routes that use API call from the server port. example :
//dev
const url = "http://localhost:5000";
//production
//const url = "";
const exampleRouter= axios.create({
baseURL: `${url}/seeSomthing`,
});
later I just use this router with get/post etc in my client side in dev mode, i use "localhost" but in production, the URL is an empty string
In server side i use as follow
const app = express();
const PORT = process.env.PORT || 5000;
// app use
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cors());
// * Step to change from dev to prod
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/build"));
}
app.listen(PORT, () => {
console.log(chalk.green("Server run on port ", PORT));
});
i guess the app.use(express.static("client/build")) doing the connection , but i try to understand what happend there?