0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

enebularでREMOTE_ADDR

Posted at

概要

enebularでREMOTE_ADDRやってみた。
phpの_SERVER["REMOTE_ADDR"]は、node-redのreq.headersで、取得できるらしい。

フロー

image.png

[{"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();
}

成果物

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?