According to How to get the full URL in Express
Let's say I have a URL:
http://localhost:3000/sample/page
import http from 'http';
const server = http.createServer((req, res) => {
let url = req.url // /sample/page
}).listen(3000)
req.url will be /sample/page
in this case
Is there any way to find out the full URL with host, port etc?
CodePudding user response:
To get the full URL, you need to get the protocol
, host
and originUrl
protocol
ishttp
orhttps
host
is the website domain.originUrl
is path
import http from 'http';
const server = http.createServer((req, res) => {
let url = req.protocol '://' req.get('host') req.originalUrl;
}).listen(3000)
var fullUrl =
CodePudding user response:
You can find your answer here. This is exactly what you are looking for.