概要
enebularでREMOTE_ADDRやってみた。
phpの_SERVER["REMOTE_ADDR"]は、node-redのreq.headersで、取得できるらしい。
フロー
[{"id":"a44f4e88.31af4","type":"http in","z":"c8bc4180.f9321","name":"","url":"/ipinfo","method":"get","upload":false,"swaggerDoc":"","x":150,"y":700,"wires":[["4974a693.d4f5d8","21c925f0.687c8a"]]},{"id":"4974a693.d4f5d8","type":"function","z":"c8bc4180.f9321","name":"ip","func":"//msg.payload = msg.req.ip;\nmsg.payload = msg.req.headers;\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":700,"wires":[["18e86d05.60ff63"]]},{"id":"18e86d05.60ff63","type":"http response","z":"c8bc4180.f9321","name":"","statusCode":"","headers":{},"x":550,"y":700,"wires":[]},{"id":"21c925f0.687c8a","type":"debug","z":"c8bc4180.f9321","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"req","targetType":"msg","x":350,"y":620,"wires":[]}]
サンプルコード
function run() {
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://ohiapp0.herokuapp.com/ipinfo", true);
xhr.onreadystatechange = function() {
if (this.readyState === 4 && this.status === 200)
{
var data = JSON.parse(this.responseText);
alert(data["x-forwarded-for"]);
}
}
xhr.send();
}
成果物
以上。