What is the equivalent to window.location.protocol
and window.location.host
in NodeJS/ExpressJS?
I'm trying to redirect the url back to my site using a third party API.
What is the equivalent to window.location.protocol
and window.location.host
in NodeJS/ExpressJS?
I'm trying to redirect the url back to my site using a third party API.
The NodeJS API url.format(urlObject) method returns a formatted URL string derived from urlObject
.
var url = require('url');
function getFormattedUrl(req) {
return url.format({
protocol: req.protocol,
host: req.get('host')
});
}
res.redirect(getFormattedUrl(req));