1

I want to use an API in my meteor app. The API is restricted to a few requests per second per unique IP.

Does anyone know if the server IP or the user IP is used, when I make an API call in Meteor.methods like this

    Meteor.methods({
        searchTerm: function (term, lang) {
            var parameters = {
                "api_key": Meteor.settings.API
            };
            try {
                var result = HTTP.call("GET", apiLink, { params: parameters });
                return result.data;            
            } catch (e) {
                return e;
            }
        }
    }

Thanks in advance.

eTomate
  • 231
  • 1
  • 11
  • Where does this code run? If on the server - it's the server's IP, if on a client - it's a client's IP. – zerkms Sep 02 '15 at 22:11
  • The code is stored in /server/lib/ so this runs on server side if I'm correct - am I ? – eTomate Sep 02 '15 at 22:18
  • Why not run it to know for sure? Like, you have code - any reason to make guesses instead of checking it? – zerkms Sep 02 '15 at 22:19
  • possible duplicate of [How to get the user IP address in Meteor server?](http://stackoverflow.com/questions/14843232/how-to-get-the-user-ip-address-in-meteor-server) – saimeunt Sep 02 '15 at 22:27
  • @saimeunt, no that's a completely different question. – Christian Fritz Sep 02 '15 at 22:28
  • The API call will be made from your server unique IP address, so every client making API calls on behalf of your server will use your server IP quota. – saimeunt Sep 02 '15 at 22:31

1 Answers1

1

As already noted in the comments, if this code (the methods call itself) is runs on the server, then the method call (later with Meteor.call) is like a remote procedure call and the HTTP will be executed on the server only. If, however, this code, the methods call, is invoked on both the client and the server, then that defines a stub (http://docs.meteor.com/#/full/methods_header). That stub is executed in parallel on the client and the server. It is meant to help with latency compensation. I don't think you want that in this case though, since you are more concerned with the number of API requests. So I would suggest to leave it where it is right now (in the server folder somewhere). That way you can be sure that it will only execute on the server and not the client, and hence use the server IP.

Christian Fritz
  • 20,641
  • 3
  • 42
  • 71