Ajitej Kaushik
Ajitej Kaushik

Reputation: 944

misreading url path as params

I have faced upon a problem which may sound weird but lot of people must be dealing with.

I have defined two routes in my routes.js file.

Route1 router.route('/atpages/:query') .get(app.oauth.authorise(), atpagesController.getAtpagesByIdOrName);

Route2 router.route('/atpages/match') .get(app.oauth.authorise(), atpagesController.matchAtpagesByUrl);

Both the routes are supposed to call different functions in controller, but the issue is whenever i hit Route2 automatically Route1 is being called. I know the issue that it is considering match as a query, my problem is that i need the routes to hit different questions without redefining their endpoints.

What i want is route should remain the same as they are but they should hit respective functions only.

TIA.

Upvotes: 0

Views: 31

Answers (1)

Natalia Cherniavskaia
Natalia Cherniavskaia

Reputation: 183

You can check if query is not equal match in Route 1 controller like this:

function getAtpagesByIdOrName (req, res, next) {
    if (req.params.query == 'match') {
        next();
    }
}

Upvotes: 1

Related Questions