banidb-api icon indicating copy to clipboard operation
banidb-api copied to clipboard

Use the URL builder in routes

Open Gauravjeetsingh opened this issue 2 years ago • 0 comments

from controller/shabad.js

    resultsInfo.pages.nextPage = `${req.protocol}://${req.get('host')}${req.baseUrl}${
            req.path
          }?${Object.keys(req.query)
            .map(key => `${key}=${encodeURIComponent(req.query[key])}`)
            .join('&')}`;

Maybe we can divide this into two different statements (for base path and query keys.

Also, can we use a URL builder instead?

Something like:

const url = require('url');
const myURL = url.format({
  protocol: req.protocol,
  hostname: req.get('host'),
  pathname: '/some/path',
  query: {
    key: 'value'
  }
});

Originally posted by @mandeepryaz in https://github.com/KhalisFoundation/banidb-api/pull/268#discussion_r1229737771

Gauravjeetsingh avatar Jun 21 '23 10:06 Gauravjeetsingh