jshttp / proxy-addr

Determine address of proxied request

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Returned Function Parameter Count From compile()

ndunks opened this issue · comments

In this code is calling trust with two arguments:

if (trust(addrs[i], i)) continue

But if look on the returned function from compile() -> compileTrust() -> trustSingle/Multi(), its just using one argument.

return function trust (addr) {

My question is, what the second parameter is used for? is safe to ignore that?

I can create PR to remove that if needed.

Compile is not called if the user supplies a trust function, and thay user-defined function can use the second parameter to make trust decisions.

So in typescript definition the second parameter of trust function can be optional?

Hi @ndunks sorry, I am not familiar with typescript.

Nope, just clarify. In internal proxy-addr is calling trust function with only one argument, right? and in user-defined function trust function "may" called with second argument? So, I think the second parameter is optional. This not affect with your repo, but I will make PR to typescript definition repo, because in that definition the the second parameter cannot be omitted even Im not use it.

I'm not sure what you are saying, exactly. Internally, this module will always provide two arguments to the given trust function: the address and the index of that address. It expects a boolean to be returned to indicate if that address is trusted or not.

The result from the compile export of this module is meant to be used as the input to the trust argument, as it will return a function that matches that signature that is expected for the trust function so you can optimize if needed.

I hope that helps.