Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Browser-sync in mobile while local development

How can I view my local dev website in my phone using gulp Browser-sync? I type localhost:3000 in my phones browser but it won't load

like image 987
SimplifyJS Avatar asked Jan 12 '16 09:01

SimplifyJS


People also ask

Why do we use browser sync?

Save time by using Browsersync's live reloading feature! No more hitting the refresh button anytime you make a small change. Changing any code, from html to css, automatically reloads the webpage when you hit save.

What is Browsersync proxy?

For frontend development, Browsersync is a helpful tool that reduces the turnaround time to a minimum while coding. While serving local files and listening to changes it can also proxy your backend URL and forward requests, which, however, doesn't work in all scenarios.


3 Answers

When you run gulp in your terminal you should see :

    [BS] Access URLs:
 --------------------------------------
       Local: http://localhost:3000
    External: http://192.168.10.81:3000
 --------------------------------------
          UI: http://localhost:3001
 UI External: http://192.168.10.81:3001

What it means is that your local URL is localhost at port 3000. For external users it will be the external IP [ not the UI one ]. To access from your phone you need to enter the External IP along with its port in your phone's browser.

You can view all your browser-sync settings by visiting the UI IP.

Note : For the external link to work on your phone, your phone and computer should be on the same Wi-Fi Network, only then it will work.

like image 58
AmitJS94 Avatar answered Oct 04 '22 07:10

AmitJS94


I know this is old, but the above option didn't work for me, and I'm running windows 10. I eventually found a solution using the tunnel option which is completely hassle-free.

For instance, setting as an option tunnel: true will generate a random public URL each time you run BrowserSync: e.g. http://randomstring23232.localtunnel.me

However, you can set a preferred tunnel name by passing it as a string to the tunnel option, i.e. tunnel: 'preferredtunnelname', which will reproduce: https://preferredtunnelname.localtunnel.me

References here: https://github.com/BrowserSync/browser-sync/issues/390 and https://browsersync.io/docs/options/#option-tunnel

like image 42
Asamoah Avatar answered Oct 04 '22 08:10

Asamoah


Thanks to @Kwesi for sharing above. In my case, setting tunnel:true alone didn't work until I also added online:true. Here's my sample code - worked fine on both computer and mobile device.

browserSync.init({
    server: {
      baseDir: "app"
    },
    online: true,
    tunnel: true,
    logLevel: "debug"
  });
like image 42
yoges nsamy Avatar answered Oct 04 '22 06:10

yoges nsamy