0
I have a validation form on React but on clicking submit m getting “404 Error”. It works perfect on local machine. //from app.js
handleSubmit = async e => { e.preventDefault(); const response = await fetch(‘/api/emailVerifier’, { method: ‘POST’, body: this.state, headers: { ‘Content-Type’: ‘application/json’, },
//body: JSON.stringify({ post: this.state.post }),
});
const body = await response.text();
this.setState({ responseToPost: body });
}; //from server.js
app.post(‘/api/emailVerifier’, async (req, res) => { console.log(req.body); const emailValidator = new EmailValidator(); const { wellFormed, validDomain, validMailbox } = await emailValidator.verify(req.body.post); res.send(
`response received , welllformed = ${wellFormed}, validDomain = ${validDomain}, validMailbox = ${validMailbox}`,
); }); i have installed my my validator on server using npm i add deep-email-validator --save
My Directory on server has
asset-manifest.json index.html manifest.json package.json static build logo192.png node_modules robots.txt favicon.ico logo512.png package-lock.json server.js
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Have you wired your backend server correctly? From the looks of it, you are attempting to serve the client and server from the same host? If so, are you pointing the server to your build correctly? Here’s a reference from the create-react-app documentation
https://create-react-app.dev/docs/deployment#other-solutions
My hunch is that your client app is the only thing deployed and your server is not running on the same host or is not setup correctly. You want your server to power the client and send the build back on non-api paths as shown in the example at the link above.
Thanks my problem is fixed. I created separate project for react and node and tried deploying using app platform. It worked. Earlier I was having single project fro both of them
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.