banidb-api
banidb-api copied to clipboard
Use the URL builder in routes
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