Report this

What is the reason for this report?

Single page react app using node api gives 404 error on Production server

Posted on December 1, 2020

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

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.