A simple app server
I was playing with Aptana over the weekend, and it’s really neat: except I currently don’t own a computer with enough horsepower to make it work worth a damn.
One thing I think is neat about IDEs and Eclipse, is their whole “internal HTTP server” thing. My users are, at times, silly, and making them maintain an Apache instance is problematic. I really wish I had a way to view content, wherever it may be, without making them (and me!) have to wrangle apache.
So here’s what I did.
1. Download and install Lighttpd. (On Tiger you will need PCRE as well, I don’t know about Leopard.)
2. I then wrote the following applescript:
tell application “BBEdit”
set theFilePath to file of active document of text window 1 of text windows
set theFileName to name of active document of text window 1 of text windows
set UnixPath to POSIX path of theFilePath
do shell script (”/usr/local/bin/startlight ” & UnixPath)
my openFile(theFileName)
end tell
on openFile(someFile)
tell application “Finder”
open location “http://127.0.0.1:8000/” & someFile
end tell
end openFile
And this is ’startlight’ referenced above:
#!/bin/sh
STARTPATH=$1
if [ ! $STARTPATH ]; then
logger “You need to enter an argument.”
echo “You need to enter an argument, probably the full path to where you want to start the httpd.”
exit
fi
rm /tmp/light.conf &> /dev/null
killall lighttpd &> /dev/null
DOCROOT=`dirname $STARTPATH`
echo ’server.bind = “127.0.0.1″‘ > /tmp/light.conf
echo ’server.port = 8000′ >> /tmp/light.conf
echo “server.document-root = \”$DOCROOT\”" >> /tmp/light.conf
echo “server.modules = (\”mod_cgi\”)” >> /tmp/light.conf
echo “cgi.assign = ( \”.php\” => \”/usr/local/bin/php\” )” >> /tmp/light.conf
echo “mimetype.assign = (\”.html\” => \”text/html\”, \”.js\” => \”text/javascript\”)” >> /tmp/light.conf
/usr/local/sbin/lighttpd -f /tmp/light.conf &> /dev/null
exit
(there may be some quoting issues there … sorry)
3. Compile the Applescript as an application; be sure to get rid of all that ’start screen’ crap. Put the startlight script in /usr/local/bin or something, make sure it’s executable.
4. Then in BBEdit, go to Preferences->HTML Preview. Set the compiled Applescript as your default HTML viewer.
Then just cmd-control-p when editing your neato thing, and boom, your default browser. This is really nice for fiddling with Google Maps and quickie JavaScript things.




You are a beast, sir.
~/Sites is for faggots.