1

On my site, I have embedded mailto links in the code. Since I want to learn some backend, and also don't want to recieve too much spam (even though it hasn't happened yet), I am going to replace those with an in-house solution. My university student counselour utilises a contact form system that let's you input your own email address, content and then essentially send it from your own email address that you entered without actually using your standard email client which this address is bound to. I figured this would be possible through usage of Nodemailer. Correct me if I'm wrong. Also screw PHP.

Actually implementing Nodemailer or another contact form solution isn't first to be done though. To prevent spambots from taking advantage of the system, I am in process of implementing the Recaptcha widget into the form. Front-end has been successfully implemented onto the domain, ableit currently disabled. As for backend, I found one decent tutorial for server-client implementation using Nodejs, others utilised PHP (did I mention screw PHP?).

Unfortunately it was not a very good tutorial unless you've done some Nodejs before. Although I know what a lot of the code does, I am slightly clueless about some bits in the code.

Basically his site is a single-page app, mine is not and rebuilding it into that is currently not a priority. First point of confusion is 5:07. I am going to implement my form into the pages index.html, about.html and work.html, or all three pages on my site, which is why I need flexible code. Due to the backend script, the node packages and the front-end scripts being in a sub-folder (/js), I also need to use this syntax which further complicates things:

res.sendFile(path.join(__dirname + '/../index.html'));

Next part that confuses me is 7:31. So if I am correct, "/subscribe" in his case is a subdirectory where the output JSON files are placed, but he never explained that properly.

Last is 18:50, but that is basically the same question as above.

No problems with installing Node or the required modules though.

The unfinished site is located on this domain: http://beta.saddexproductions.com. Function is launched with the "email me"-button at the bottom of the page.

The front-end script is located at http://beta.saddexproductions.com/js/lang.js. Ctrl+F:

 $(document.body).on('mousedown','#send', function(e){

The back-end script is located at http://beta.saddexproductions.com/js/server.js. This is just a dummy script, with the private key removed. The rest of the code is the same as in the true script.

Saddex
  • 117
  • 1
  • 11
  • the __dirname line just tells the app that your file is located in a particular directory in relationship to the entry point of your app. so if you have a directory with server.js, a folder called routes, another folder called public, you would use res.sendFile(path.join(__dirname + '/public/index.html')) if your index.html was located inside public. /subscribe is not a directory so much as it is a route on the server that you can make a request post to. How it works is the user sends a request and the server does stuff depending on the headers and body of the request, then sends a response. – LJD Jul 29 '18 at 20:52
  • Read some of the express docs: https://expressjs.com/en/guide/routing.html – LJD Jul 29 '18 at 20:58
  • Since dealing with `Node.js`, you should also read about package management, that's `npm` for `Node.js`. https://www.npmjs.com. There is a package for implementing re-captcha to your `Node.js` application: https://www.npmjs.com/package/recaptcha – B_CooperA Jul 30 '18 at 05:01
  • @JudeDesir I did try reading the docs and updated the scripts accordingly. Route is now set to '/'. However, this results in a 405 "method not allowed" error. The code is accessible in the linked files as before (this includes the dummy script not actually being executed. Post is specified in both front and back-end, but the get included from the tutorial might cause the error. Also, just like you can do with vanilla JS or Jquery, is it easy to use an array to specify which file you want to send? Thanks for the reply anyways. – Saddex Jul 30 '18 at 20:38
  • @B_CooperA I did read that, and it did sound promising, until I read that it (currently) only works for reCaptcha version 1.0. My site uses 2.0, the (usually) less annoying variant that tends to be one-click. Thanks for the reply regardless. – Saddex Jul 30 '18 at 20:44
  • @JudeDesir Could [the solution here](https://stackoverflow.com/questions/47776160/nodejs-express-handling-404-not-found-and-405-method-not-allowed-separated) eventually work in this case for getting rid of the errors or is just the route inproperly called? – Saddex Jul 31 '18 at 18:02

0 Answers0