【发布时间】:2020-05-26 14:01:34
【问题描述】:
我正在为一个非常简单的网络应用程序使用 node 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);
【问题讨论】:
-
注意:代码
new(nodeStatic.Server)()不正确。应该是new nodeStatic.Server()或new nodeStatic.Server(path)。
标签: node.js node-static