My scenario:
I can make a call to my app in port 3000 (with Postman, Chrome, Curl)
I gave my private IP (10.16.x.x) to my friend using same LAN network
Could you please tell me how can I face with this problem? May I use Nginx in my case?
Sounds like firewall blocking external requests to your port. If you use Ubuntu, you can allow port with ufw. Alternatively, you can use ngrok.io to expose app to public.
@lOlbas, thank you a lot for your comment. I tried to use simpleHTTPserver or simple app built with create-react-app, and I gave my IP to my friend in same LAN network, he/she still can connect but for Serverless Offline, it does not work, how weird it is !
And I do not want to use Ngrok because I concern about exposing to the public network.
About ufw I will try tomorrow because I am not in my office at the moment and I will feedback you soon.
@bugb what was the port for react app?
@lOlbas I can use any port > 1234 for my react app and my friend in same LAN network can access it.
I tried to run serverless offline with port 3000 and gave my IP address for my friends, but they can not access it.
I'm closing the issue since this is not an issue with your plugin but rather with your network.
@dherault correct me if I am wrong here but this has nothing to do with the OP network.
serverless-offline uses Hapi to create the server for offline use. According to Hapi documentation (and I have never used Hapi before) the server.option.address parameter is 0.0.0.0 by default, unless host is present, in which it will use that value. It then goes on to state:
Set to '127.0.0.1' or 'localhost' to restrict the server to only those coming from the same host.
serverless-offline by default sets host to localhost therefore blocking all traffic not on the same host.
The "fix" is to set -host 0.0.0.0 and it will therefore be open - that will the show a Serverless: Offline listening on http://0.0.0.0:3000 however.
There is no fix to this as it is doing exactly as it should be doing - however the documentation isn't clear, and by the fact it was blamed on a network issue seems to prove that.
@amwill04: Thank you a lot for your solution.
I just made another one.
Here is my solution if anyone encounter with my problem:
nginx in your local computer, you can use Docker/etc/nginx/nginx.confhttp block:server {
listen 80;
server_name your_lan-ip_here;
location / {
proxy_pass http://localhost:3000;
}
}
Change your_lan-ip_here with your LAN ip example: 10.16.38.95.
Here my Nodejs app is running in port 3000 so I have proxy_pass http://localhost:3000, change 3000 to your correct port!
Have fun!
-host 0.0.0.0
this is actually --host 0.0.0.0
Or in your serverless.yml:
`custom:
serverless-offline:
httpPort: 4001
port: 4001
host: 0.0.0.0
resourceRoutes: true`
Most helpful comment
@dherault correct me if I am wrong here but this has nothing to do with the OP network.
serverless-offlineusesHapito create the server for offline use. According toHapidocumentation (and I have never usedHapibefore) theserver.option.addressparameter is0.0.0.0by default, unlesshostis present, in which it will use that value. It then goes on to state:serverless-offlineby default sets host tolocalhosttherefore blocking all traffic not on the same host.The "fix" is to set
-host 0.0.0.0and it will therefore be open - that will the show aServerless: Offline listening on http://0.0.0.0:3000however.There is no fix to this as it is doing exactly as it should be doing - however the documentation isn't clear, and by the fact it was blamed on a network issue seems to prove that.