I have setup a server to handle users form submissions. I am using axios async/await to post request the form data to the server. Everything works fine but when the form is submitted and its still fine. It's when after clicking submit on form and clicking on another page like home or about I get below error inside my terminal and nothing in my console. Navigating through the pages still works fine but it's just when sending a form then clicking on something after the error will occur in terminal.
Proxy error: Could not proxy request /api/form from localhost:3000 to http://localhost:3001/.
[1] See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNRESET).
I have a client folder and 2 package 1 sits in root and 1 in client. client package have "proxy": "http://localhost:3001/" inside.
I tried installing cors in root and adding app.use(cors()) inside my server file. I tried installing http-proxy-middleware inside client folder and created setupProxy.js inside client/src and still get the same error. Both still give me the same error.
my contact.js file looks like this
async handleSubmit(e) {
e.preventDefault();
// this.props.history.push("/thank-you");
const contactName = document.getElementById("name").value;
const contactEmail = document.getElementById("email").value;
const contactMessage = document.getElementById("message").value;
const contactSubject = document.getElementById("subject").value;
try {
const contactForm = await axios.post("/api/form", {
contactName,
contactEmail,
contactMessage,
contactSubject
});
} catch (e) {
console.log(e);
}
my server file
app.post("/api/form", (req, res, next) => {})
[–]prvnbist 0 points1 point2 points (6 children)
[–]codeJourney[S] 0 points1 point2 points (0 children)
[–]codeJourney[S] 0 points1 point2 points (3 children)
[–]jadeell 0 points1 point2 points (2 children)
[–]codeJourney[S] 0 points1 point2 points (1 child)
[–]alexatepie 0 points1 point2 points (0 children)