Skip to content

Instantly share code, notes, and snippets.

@pascaliske
Last active August 21, 2017 20:41
Show Gist options
  • Save pascaliske/2d37fe363ecea49e3835ba7dbda31ef9 to your computer and use it in GitHub Desktop.
Save pascaliske/2d37fe363ecea49e3835ba7dbda31ef9 to your computer and use it in GitHub Desktop.
Local Network BrowserSync Proxy

Local Network BrowserSync Proxy

Update: I've published a npm package for an even easier usage of this trick! See pascaliske/bsproxy.

Quickly proxy a local domain (e.g. http://my-site.dev) for local network access.

Steps

  1. Globally install BrowserSync

    $ yarn global add browser-sync
    

    OR

    $ npm i -g browser-sync
    
  2. Copy the script bsproxy to your binaries folder (/usr/local/bin)

    $ curl -L https://gist.github.com/pascaliske/2d37fe363ecea49e3835ba7dbda31ef9/raw/bsproxy >> /usr/local/bin/bsproxy && chmod +x /usr/local/bin/bsproxy
    
  3. Run the command

    $ bsproxy http://my-site.dev    

  1. If BrowserSync doesn't show you your correct ip, you have to manually replace localhost with your ip in your local network

Tip: You can change BrowserSync's port:

    $ bsproxy http://my-site.dev 8080    

#!/bin/bash
if [[ $1 != '' ]]; then
if [[ $2 != '' ]]; then
browser-sync start --no-open --no-ui --port $2 --proxy "$1"
else
browser-sync start --no-open --no-ui --port 9001 --proxy "$1"
fi
else
echo "BrowserSync Proxy"
echo ""
echo " usage:"
echo " $ bsproxy <url> [<port>]"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment