Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
44
rated 0 times [  51] [ 7]  / answers: 1 / hits: 19047  / 8 Years ago, tue, july 19, 2016, 12:00:00

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.


More From » node.js

 Answers
4

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));

[#61314] Saturday, July 16, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
deonkalvinw

Total Points: 409
Total Questions: 96
Total Answers: 89

Location: Saint Pierre and Miquelon
Member since Sun, Nov 27, 2022
2 Years ago
deonkalvinw questions
Sun, Feb 6, 22, 00:00, 2 Years ago
Tue, Dec 28, 21, 00:00, 2 Years ago
Sun, Aug 22, 21, 00:00, 3 Years ago
Sun, Mar 7, 21, 00:00, 3 Years ago
;