crash springfield
crash springfield

Reputation: 1082

get request query string node

I'm using nodemailer to verify user's email when they sign up. It sends out an email with a link (something like localhost:3000/verify/?id=##).

When they click the link, it works and I can see a GET request has been made.

GET /verify/?id=141 200 2.582 ms - 4638

I tried this:

api.get('/verify/?id=', function(req, res) {
    console.log('verify request has been made'); // doesn't log on console
})

And I also tried this:

api.get('/verify', function(req, res) {
    console.log(req.query.id);
    console.log(req.param.id);
})

based on answers to questions I'd seen answered here and elsewhere, but nothing gets logged.

Also, I'm using Angular (with ngRoute) so it might be something going on on the frontend too, but I'm new to MEAN stack and don't know where to begin.

edit Here's the front-end:

app.routes.js

angular.module('appRoutes', ['ngRoute'])
 .config(function($routeProvider, $locationProvider) {

  $routeProvider
    .when('/', {
      templateUrl: 'app/views/pages/map.html',
      controller: 'MainController',
    })
    .when('/verify/:username', {
      templateUrl: 'app/verify/verify.html',
      controller: 'verifyController'
    })
  $locationProvider.html5Mode({ enabled: true, requireBase: false });;
})

verifyController.js

angular.module('verifyController', ['verifySerivice'])
  .controller('verifyController', function($routeParams, verify){
      console.log('in verify controller');
      var id = $routeParams.id;
      verify.verifyUser(id);
})

verifyService.js

angular.module('verifyService', [])

  .factory('verify', function($http) {

    var verifyFactory = {};

    verifyFactory.verifyUser = function(id) {
      console.log('verify service accessed');
      return $http.get('/verify', id)
        .then(handleSuccess, handleError);
    }

    return verifyFactory;
  })

Upvotes: 1

Views: 83

Answers (1)

J_Everhart383
J_Everhart383

Reputation: 354

Can you provide the routing code and the code you are using to make the request? If Angular is handling your routing, the request may never actually make it to the Node server if you are requesting the URL through the address bar of the browser. If you are using the http module to make a get AJAX request, that would be helpful as well to see.

Upvotes: 1

Related Questions