繁体   English   中英

节点 static 服务于不同的索引。html 用于某个 IP 地址

[英]Node static serve different index.html for a certain IP address

我正在为一个非常简单的 web 应用程序使用节点 static。

我需要为某个客户端 IP 提供不同的 index.html 服务。

这是我的代码自动取款机:

var fileServer = new(nodeStatic.Server)();
var app = http.createServer(options, function(req, res) { 
    // Office IP so I dont need code
    var staticIp = "111.11.11.11"; 
    var securityCode = "SECRETKEY";
    if (staticIp == req.headers['x-real-ip']) {
        // TO DO: Server an other index.html
    } else if (req.url.includes(securityCode)) {
        fileServer.serve(req, res);
    } else {
        res.writeHead(200, {"Content-Type": "text/plain"});
        res.write("Access Denied");
        res.end();
    }
}).listen(8443);

文件说:

如果要提供特定文件,请使用 serveFile 方法:

例如:

fileServer.serveFile('xyz.html', 200, {}, request, response);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM