有没有办法让 url 客户端在发送请求时打开

Is there a way to get the url the client was on when a request was sent

我正在尝试获取客户端在请求 manifest.appcache 文件时所在页面的 url。

我试过了

var fullUrl = req.protocol + '://' + req.get('host') + req.originalUrl;

但是当我这样做时我得到了请求文件的 url (localhost:1337/manifest.appcache)

我想要的是类似localhost:1337/mushroom/ 或 localhost:1337/gingerbread/ 即发送请求时用户所在的页面

Referer HTTP 请求就是您要查找的内容。

不使用 req.originalURL,而是使用 req.get('referer')

来自 MDN 网络文档:(link)

The Referer request header contains the address of the previous web page from which a link to the currently requested page was followed. The Referer header allows servers to identify where people are visiting them from and may use that data for analytics, logging, or optimized caching, for example.

我在我的网站上使用它来将用户重定向回他们登录后所在的页面。 编码愉快!