The Cranky Sysadmin A world of technology, fun, and ignorant rants.

December 7, 2009

Steps Closer to mod_js for Apache

Filed under: Programming — Cranky Sysadmin @ 7:35 pm

I started out thinking that I’d learn JavaScript so that I could make AJAX games. I am ending up in the land of C programming while trying to get a functional mod_js running.

To be useful, JavaScript needs access to server-side resources which are either missing or disabled in the usual build. I downloaded the latest SpiderMonkey (C based JavaScript engine), and built it. After a few hours of work, I produced a patch to enable the file handling module. I also had to install the nspr4-dev package. If you manage to use this patch on a recent SpiderMonkey, you may want to look at this page. It seems to be a fairly complete description of the File object API.

Once I got SpiderMonkey running, I plopped the js shell binary and the libjs.so library where the OS can reach them and started looking for a mod_js. I didn’t hold out much hope of finding one since I’ve looked for this in the past. Lo and behold though, someone had done some work in this area. It looks like active work stopped in mid 2007. There is a checkin which changed the license to a dual GPL/Apache license. I checked out the source and got it running after several more hours of work. I produced a patch to keep it from crashing on my Ubuntu system.

I ended up with a minimal mod_js which can handle files. I have a lot of work to make it really useful. Short term goals include setting up some system where tags set off the JavaScript from the content. PHP uses <? and ?> to delimit code. I’ll probably do something similar. There are the beginnings of SQLLite support in the mod_js code. I have no idea how complete the support is, but I’d like to get that running. I’d also like to add bindings for MySQL and PostgreSQL. If possible, I’ll try to build a set of modules which attach to the SpiderMonkey engine instead of attaching to mod_js. That way, the extended SpiderMonkey can be used for other projects easily.

As I move forward, I’d like to offer thanks to the folks at Mozilla for writting a nice C based JavaScript engine. I’d like to also thank the folks at modjs.org for writting something which functions and looks easy to extend. If either of the authors listed are around and happen to read this, I’d be happy to pass along any patches. If I don’t hear from them, I’ll build a repository and make it accessible. The folks at FreeSWITCH seem to have well written docs on the File object. I’ll probably look at their rendition of the SpiderMonkey engine and see if I can avoid some work.

In a future article, I’ll try to write up some docs for building SpiderMonkey and mod_js from a Ubuntu user’s perspective.

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress