首页 > 解决方案 > Expressjs 无法获取来源或引用者

问题描述

当点击指向我网站的链接时,是否可以找出用户来自哪里?

让我们假设我拥有并放置http://example.com了一个链接( ) 。.net 不是我的网站http://example.com/foobarhttp://example.net/path/to/subsite

现在,当访问者来自example.net点击链接。我能以某种方式获得起源吗?

我使用 express js 运行网络服务器,但我不知道我在这里做错了什么。

const express = require('express')
const router = express.Router()
router.use(function (req, res, next) {
  const origin = req.get('origin')
  const host = req.get('host')
  // Nothing here tells me the origin.
  console.log(origin, host, req.headers)
})

标签: node.jsexpress

解决方案


这将为您提供调用 Express.JS API 的 URL

req.headers.referer;

推荐阅读