0

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.

Calaf
  • 10,113
  • 15
  • 57
  • 120
  • Why don't you just use a browser extension to simulate the mobile usage...? – Thomas Ayoub Jun 23 '15 at 13:48
  • interesting.. I'm now wondering what the browser extensions would give me. Would it be enough to just reduce the size of the browser window as a way of simulating what would be rendered on a mobile device? (or, alternatively, magnifying the fonts, since some mobile devices have resolution higher than my desktop.) – Calaf Jun 23 '15 at 14:10

1 Answers1

0

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

sweepy_
  • 1,333
  • 1
  • 9
  • 28
  • All right, so after launching a server on localhost I'll see the site from each mobile device. But how do I launch a server from the command line? Also, I see "Wi-Fi is connected to foobar and has the IP address a.b.c.d, where a.b is *not* 192.168. Then I'm not clear from your answer whether I should point to a.b.c.d or to 192.168.x.y, and what x.y should be. – Calaf Jun 23 '15 at 14:07
  • You should access a.b.c.d, sorry for the bad example! To run your server, you'll need something like MAMP or use technologies such as NodeJS able to start a web server themselves. – sweepy_ Jun 23 '15 at 14:09
  • I'm really hoping I don't have to go through MAMP (or any GUIs) for this. Is there a macports package that'll do it? Is the osx webserver that gets launched under "sharing" accessible from the command line? – Calaf Jun 23 '15 at 14:12
  • 1
    Please check that link to find-out how to run a web server quickly from your Terminal: http://osxdaily.com/2012/09/02/start-apache-web-server-mac-os-x/ – sweepy_ Jun 23 '15 at 14:14
  • That's a nice reference for starting (and shutting down) apache from the command line. The trouble is that it requires editing a file in `/etc/apache2/users` and pointing to a new html page instead of ~/Sites. It's all right, but if I'm going to edit a file in an rwxr-xr-x (644) directory, I might as well add a small local python file and launch a WSGI server. Either way, I still don't understand the pattern behind the possible 192.168.x.y addresses. – Calaf Jun 23 '15 at 14:25