1
I’m deploying a project that has Front in React and Back in Nodejs, but my host (Kinghost) asks me to deploy the Node app and within the same folder put the React Build, the FTP looks like this:
Within Node index.js, I’m pulling the build index.html as follows:
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
And this works very well, the home screen is Login, I can log in and drop off, show information from the bank, the problem is that on a page I have a Register button, and this registration is on route
<Container maxWidth="lg">
<Switch>
{ !currentUser &&
<Route exact path={`${process.env.PUBLIC_URL}/`} component={Login} /> }
{ showCadastroBoard &&
<div>
<Route exact path={`${process.env.PUBLIC_URL}/cadastro`} component={BoardCadastro} />
<Route exact path={`${process.env.PUBLIC_URL}/`} component={CompreBem} />
</div> }
{ showComumBoard &&
<Route exact path={`${process.env.PUBLIC_URL}/`} component={CompreBem} /> }
{ showAdminBoard &&
<Route exact path={`${process.env.PUBLIC_URL}/`} component={BoardAdmin} /> }
{ showTesteBoard &&
<Route exact path={`${process.env.PUBLIC_URL}/`} component={BoardTeste} /> }
</Switch>
</Container>
When I click on this button to go to the registration page, the following error appears in the console:
Failed to load resource: the server responded with a status of 404 (Not Found)
and is on a page with "cannot GET /register".
What I do?