Reputation: 85
I have successfully created a Node.js server with Express and also installed nodemailer to send the data from the 'Contact Me' form from my front-end React app. I have uploaded this on Heroku.
I have a question though - since this endpoint is set up on this public domain, in theory, someone could inspect my source code, find the URL, and build a script out to make a ton of POST requests with random data to blow up my inbox.
Is there anything that can be done to stop this sort of behavior? Where would I even start to research into this?
Upvotes: 0
Views: 270
Reputation: 1183
CORS is what you're looking for. I recommend reading up a lot more on it since it will pay off greatly for your web development journey! https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
The short answer is that you must set a Access-Control-Allow-Origin: <yoursite>.com
header in CORS policy for your Node.js app (install it from npm), which will turn down any requests made by a 3rd party actor who inspects the form destination address.
Upvotes: 1