- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我的网络应用程序以这种方式管理用户的个人资料:
username.mywebsite.com
我使用子域表达模块来管理它,它工作得很好。 (https://www.npmjs.org/package/subdomain)
var subdomain = '/subdomain/:profileurl';
app.get(subdomain+'/user-home', main.isThisProfileExist, main.getHome);
app.get(subdomain+'/user-info', main.isThisProfileExist, main.getInfo);
app.get(subdomain+'/user-data', main.isThisProfileExist, main.getData);
...
但是,很少有用户有权将他们的个人资料与他们的自定义域名 (CNAME) 链接起来,这就是我的问题开始的地方:我找不到让我的快速路由发挥作用的方法。所以我正在考虑一种方法来伪造expressjs的req.host值。但我认为这不是最好的继续方式。
例如,用户为其域名添加了此 CNAME 记录:
customdomain.com CNAME username.mywebsite.com
但是在express中我会得到req.host值:
customdomain.com
这是逻辑,但它不符合我对这种情况的需要,因为我无法知道哪个配置文件是目标......
你有什么想法可以帮助我吗?
谢谢
最佳答案
如果您不希望用户必须告诉您他们的自定义 CNAME 是什么,您可以在收到的主机上自行执行 DNS 查找。
类似于:
var dns = require('dns');
var domains = dns.resolveCname(req.host);
您可以使用 connect 轻松地将其添加为您自己的中间件:
app.use(myCustomDomainLookup());
中间件模块中的实现可能如下所示:
var dns = require('dns');
module.exports = function () {
return function (req, res, next) {
if (!recognisedSubdomain(req.host)) {
var domains = dns.resolveCname(req.host);
var validProfiles = domains.map(main.ifThisProfileExists);
req._profile = validProfiles[0]; // Picking first valid profile
}
next();
}
}
编辑:
为了清楚起见,在此处添加注释中的代码。
要与您的子域中间件集成,您需要覆盖 req.host。这意味着您的中间件需要在子域中间件之前使用
。
您应该能够按如下方式调整上面的“if” block :
if (!recognisedSubdomain(req.host)) {
var domains = dns.resolveCname(req.host);
req.host = domains[0];
}
由于resolveCname 的文档表明可以返回一系列域,因此您必须决定在返回多个域时要执行的操作。
关于node.js - 在 Express 上伪造 req.host 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22727953/
我对 FakeItEasy(或其他模拟对象,因为我相信它们非常相似)有疑问。以下是我的 puesdocode: public class Service { public void Check
我想使用鼠标/键盘伪造操作(或触摸)事件。当我尝试使用以下方法引发事件时: RoutedEventArgs e = new RoutedEventArgs(ManipulationStartedEve
出于某种原因,我的 SVN 存储库的本地副本停止将父目录识别为工作副本。我通常会通过再次 checkout 到另一个文件夹并用我更改的文件覆盖新的工作副本来解决此问题。然后我会从新文件夹中进行提交。
我正在尝试设置我的开发实例,以便我可以伪造一些我拥有的网址。我的网站有许多网址,根据您访问的网址,我的网站的行为会因域的不同而有所不同。 我编辑了我的 C:\WINDOWS\system32\driv
当用户登录并选中“记住我”框时,我会为它生成一个 key (md5 上非常随机的数字)并保存在它的 cookie 上。如果用户未登录,我的代码会检查“记住我的 key ”cookie,如果它与用户匹配
有没有办法强制 Oracle 也“看到”一个表和相关索引比它们实际更大? 换句话说,有没有办法“伪造”数据库统计信息,因此基于成本的优化器会在几乎为空的数据库上做出决策,这更接近于在真实的大型生产数据
这是我使用 tsqlt 的第一天,所以你可能会看到一些含糊的陈述。 我正在尝试测试一个具有 Try Catch Block 的存储过程,但测试中的实际语句是插入和更新命令。 现在我想测试如果出现 Er
我从mockito开始,想知道如何假装添加观察者。我想编写一个测试来确保观察者计数在函数调用后增加。 示例测试代码: MyClassUnderTest instance = new MyClassUn
我是一名 C# 游戏开发人员,我有一个安全功能,我的服务器动态创建一个包含一些 key 的 DLL,并将这个 DLL 上传到 amazon s3,然后向人们提出挑战随机的。当客户收到此质询时,他们有
我正在尝试“伪造”一个 Canvas ,目的是将这个伪造的 Canvas 交给一个可能是任意的框架,以对所有直线、曲线和 moveTo 进行后处理。 为了解决这个问题,我尝试了这段代码,它确实有效,但
我的应用程序需要 SQL Server 2000 作为数据库存储。我真的不想使用 SQL Server 2000,但我可以改用 MySQL Server。 应用程序使用 ODBC 连接到 SQL Se
我有一个下拉菜单,需要一个带有左右边距的滚动条。我正在使用-webkit-scrollbar,但据我所知,它只支持沿滚动轴的边距,所以我一直在用容器内元素的右边距来近似水平边距,并在外部 div,如您
作为我学生小组业余项目的一部分,我正在创建微 Controller 有线网络的模拟,以测试我们编写的算法。每个 Controller 都连接到多个数据端口,每个端口都有一个输入和输出流。我通过给每个端
我已经在 Forge 中安装了自定义 SSL 证书。现在我的网站宕机了 -_-。 Site is not available connection refused 我已经重新启动了我的服务器,但没有任
我正在开发具有 ListView 和详细 View 的应用程序,并且我从 ListView 到详细 View 设置动画。在执行此操作时,我想在某个阶段隐藏状态栏(最好同时在后台显示 ListView
我想用它在 MS-Test 单元测试中伪造 System.Net.Mail.SmtpClient。为此,我添加了一个 System.dll 的 Fakes Assembmly。然后我创建一个 Shim
在我的 Playframework 2.4 项目中,我有这样的方法: public static Result resetValue(int client) { String received
这是我渲染场景的过程: 绑定(bind) MSAA x4 GBuffer(4 种颜色附件、位置、法线、颜色和无光照颜色(仅天空盒。我还有一个深度组件/纹理)。 绘制天空盒 绘制地理 将所有颜色和深度分
我不太确定 $_SESSION 在 PHP 中是如何工作的。我假设它是浏览器上的 cookie 与服务器上的唯一 key 匹配。是否可以伪造并绕过仅使用 session 来识别用户的登录。 如果 $_
大家好,我是沙漠尽头的狼。 本文首发于 Dotnet9 ,介绍使用 Lib.Harmony 库拦截第三方 .NET 库方法,达到不修改其源码并能实现修改方法逻辑、预期行为的效果,并
我是一名优秀的程序员,十分优秀!