UPDATE —
You don't need this sorcery anymore as the functions host now listens on 0.0.0.0:7071
by default:
$ func -v
2.0.1-beta.33
$ func | grep Runtime
Function Runtime Version: 2.0.11933.0
$ func host start | grep -i listen
Listening on: http://0.0.0.0:7071
NOW DEPRECATED —
If you're on Windows,
C:\>netsh interface portproxy add v4tov4 listenport=8081 ^
listenaddress=0.0.0.0 connectport=7071 connectaddress=127.0.0.1
C:\>netsh interface portproxy show all
Listen on ipv4: Connect to ipv4:
Address Port Address Port
--------------- ---------- --------------- ----------
0.0.0.0 8081 127.0.0.1 7071
C:\>netstat -an | findstr 8081
TCP 0.0.0.0:8081 0.0.0.0:0 LISTENING
C:\>netstat -an | findstr 7071
TCP 127.0.0.1:7071 0.0.0.0:0 LISTENING
To test it out:
C:\>curl.exe http://192.168.111.4:8081/api/HttpTrigger -i
HTTP/1.1 200 OK
Date: Wed, 28 Mar 2018 18:25:31 GMT
Content-Type: application/json; charset=utf-8
Server: Kestrel
Transfer-Encoding: chunked
"Oh hai."
To get rid of portproxy:
C:\>netsh interface portproxy delete v4tov4 listenport=8081 listenaddress=0.0.0.0
On Linux, iptables your way through it, on a Mac... i don't know, nginx your way out? Okay, there seems to be a pfctl
tool, probably inherited from BSDs?
Although Kestrel is the server, setting the environment variable ASPNETCORE_URLS="http://*:7071"
has no effect. The function host is probably bootstrapped with localhost
in code, which may be a hint that you're not supposed to expose it naked and you should reverse proxy into it.