node.js - Expressjs 无法获取来源或引用者
问题描述
当点击指向我网站的链接时,是否可以找出用户来自哪里?
让我们假设我拥有并放置http://example.com
了一个链接( ) 。.net 不是我的网站http://example.com/foobar
http://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)
})
解决方案
这将为您提供调用 Express.JS API 的 URL
req.headers.referer;
推荐阅读
- c# - 检查哪个数组的值为 0
- java - 为什么我使用大于 12.02 的 JAVAFX 版本会得到 GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
- javascript - 使用克隆元素将文件名传递给输入文本
- javascript - Mongoose 用于同一连接的多个模型
- postgresql - 使用 Terraform 在 AWS RDS PostgreSQL 上启用 PostGIS
- spring-boot - 通过使用 Docker-Compose 和 Spring Boot 运行的 IP 地址访问远程主机中的 Kafka
- ionic-framework - 未捕获(承诺):错误:无法匹配任何路由。URL 段:'tabs/tab1'
- python - 如何在 Python 中创建自定义类型验证函数?
- esper - esper 查询执行了一半——实际上只有一部分在运行
- json - 如何在没有占位符的情况下更改空手道 DSL 中文本响应的所有外观?