javascript - POST request 404 (Not Found) with angular.js and ExpressJS -


I am trying to send an application requesting access to my ExpressJS server using AngularJS:

 < Code> angle controller ('app') controller ('contactCtrl', function ($ radius, $ http) {$ scope.envoyer = function (enrollment, organization, dog, telephone, message) {$ http.post ('/ contact ', {Nom: nom, organization: organization, courriel: courriel, telephone: telephone, message: message}). Then (function (error, response) {if (response.data.success) {console.log (' sent! ');}}}}}};  

This is the code from the server:

  var mail Var = EMAIL_ACCOUNT_EMAIL = 'aaa@gmail.com'; Var EMAIL_ACCOUNT_PASSWORD = 'AAA'; Var smtpTransport = mailer.createTransport ({Service: "Gmail", Authentication: {User: EMAIL_ACCOUNT_EMAIL, Pass: EMAIL_ACCOUNT_PASSWORD}}; app post ('/ contact', function (rik, ridge, next) {var success = true; var mail option = {to: 'azez@email.com', subject: 'qsdxwccvfd', Html: 'sqdqsdq'}; smtpTransport.sendMail (mail option, function (error, race) {if (error) {console.log ('[error] message not sent:', error); Success = false;} else {console.log ('[INFO] message sent:' + res.message);} next (error, success);});});  

After requesting a server, I get this error message on the client side:

  POST http: // localhost: 3002 / contact 404 (not Found) Angular JS: 8495 (anonymous function) angular JS: 8495 Send Angular Angular JS: 8291 $ http.serverRequest angular.js: 8025 Coated Callback Angular JS: 11498 Wrapped Callback Angular JS: 11498 (anonymous function) angular JS: 11584 Area: $ eval angular.js: 12608 Scope $ Digest angular JS: 12420 Area Apply $ angular.js: 12712 (anonymous function) angular.js: 18 980 jQuery.event.dispatch jquery.js: 4409 elemData .Dilled  

I think this Angulus code Is coming from the fourth line, but I was not able to decide how to fix it. How can I fix this?

To send successful answers in the browser, call next Should be replaced in such a way:

  res.set ('Content-type', 'application / json'); // Show angular that this is JSON res.send (JSON.stringify ({success: success});  

Express these rows to return a marked response as a success With an object that is in JSON format with an object that contains only "success" property.

However, to work for it, you will get the smtpTransport.sendMail Will need to rename the parameters used in the callback, because you Has called that res and therefore it is currently hiding from middleware to res object so replace the header of that function like this:

< Pre> smtpTransport.sendMail (mail option, function (error, mailer) {...

... and then of course you res Instead, you will need to change the log line using mailRes .


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

c# - Create dynamic LINQ query expression at runtime which translates into a parameterized SQL query for nullable types -

cmake - cpack generates RPMs with %files entries that conflict with the RPM spec. How to fix? -