Saturday 15 April 2017

How to catch subsequent API signatures ?

I am creating an API server with user provided routes. I am stuck how can I write routes that user defined routes are dynamically handled, if the precedent route matches user's token.

I have tried two approaches, One with :params, but that doesn't work as desired as a user might input multiple levels of routes.

router.all('/api/:apikey/:fakeapi', function (req, res, next) {
  logger.debug(`API Key: ${req.params.apikey}, Requested URL: ${req.params.fakeapi}`);

  res.send(`API Key: ${req.params.apikey}, Requested URL: ${req.params.fakeapi}`);
});

Above code, works if route /api/378929832/fine, but fails when route is somehting like api/378929832/fine/with/me.

How can I make it handle all subsequent /xyz/xyz/xyz/... if the precedent API signature matches it.



via errhunter

No comments:

Post a Comment