我正在将 node static 用于一个非常简单的 Web 应用程序。
我需要为某个客户端 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);