How to serve a local website (i.e. file://) from OS X to mobile devices?

410 views Asked by At

As I edit some html/css files, I'd like to see not just how they appear on a mac (by pointing to file://) but also how they appear on a couple of mobile devices.

How do I launch from the OS X terminal a web server and point it to the root of the html pages? I'd much rather not have to go through the preferences menu and I'd much rather be able to point from the command line to any page rather than have to move whatever I'm writing to ~/Sites.

Also, I understand that there is a magical IP address starting with 192.168.x.y where each mobile device (connected to the same router as the mac) would see the pages. I'd appreciate understanding the list of useful x.y values, or a pointer to a good reference where they are defined.

1

There are 1 answers

5
sweepy_ On

If your site is running on localhost:8888 (or another port), you can access it from your device, assuming your connected on the same router, via your local Mac IP. You can find it into Settings > Network, then select your active connection on the left pane and see the IP Address field. Now on your device, access http://192.168.X.X:8888 and you should see your site running.

enter image description here

Another good option for development purpose is to use Chrome Web Inspector, that allows you to scale your screen to mobile and tablet devices by clicking the tablet icon on the top left corner of the inspector (refresh your page after having clicked). It also send the correct user-agent, very useful for most websites that don't care about responsive display but about other problematics too. You should see something like this:

Switch to responsive

Responsive display