Serverless-offline: Using Serverless Offline in LAN network

Created on 9 Apr 2019  路  9Comments  路  Source: dherault/serverless-offline

My scenario:

  • I use Serverless Offline to run my app that expose port 3000
  • 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

  • She makes a call to my app via port 3000
  • It does not work

Could you please tell me how can I face with this problem? May I use Nginx in my case?

Most helpful comment

@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.

All 9 comments

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:

  • Install nginx in your local computer, you can use Docker
  • Open the file /etc/nginx/nginx.conf
  • Add this code under http 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`

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stonebraker picture stonebraker  路  3Comments

Rafaelsk picture Rafaelsk  路  4Comments

conradoramalho picture conradoramalho  路  3Comments

FranzSkuffka picture FranzSkuffka  路  3Comments

aldofunes picture aldofunes  路  3Comments