Serving Static Files in LAN
While working on web UIs, it is often convenient to serve static files over HTTP in the local network, in order to test on multiple devices.
To serve a particular directory on your system, you have to specify it in the Apache HTTP server configuration file located at:
Change these two lines (170 and 197 in my case):
DocumentRoot "/Library/WebServer/Documents"<Directory "/Library/WebServer/Documents">
… to point to your desired path:
DocumentRoot "/path/to/your/site"<Directory "/path/to/your/site">
Start the server:
% sudo apachectl restart
Now you can browse to
http://YourComputerName.local with your phone or tablet to check your responsive design (located at
/path/to/your/site on your Mac).
Trivial, of course, but I kept forgetting. Maybe now, having it noted here, on the next, rather rare, occassion, when I have to fiddle with CSS, I will remember.
var http =var st =http
Start the server (as
root because of port 80):
% sudo node stserver.js
http://YourComputerName.local to test.
Less fluff, more buff! The st module serves static files, does etags, caching, etc. In fact, it also comes with a CLI—so, if installed globally:
% npm install -g st
… you can spawn a server from the command-line:
% sudo st -p 80 -d /path/to/your/site
What about Python? I cannot withhold the simplest way to serve the current working directory on OS X:
% sudo python -m SimpleHTTPServer 80