Archive | June, 2009

Nginx Proxies with FirePHP

16 Jun

FirePHP_Large_WhiteFirePHP is a great plugin for php+ajax devs — in essence, it captures error and logging output and sends it over HTML headers instead of the content body. These logs show up in your firebug console alongside your javascript logs, making it great for ajax development. You want your output clean but your error and logging info accessible, and lets face it, tail -f is just not as sexy as firebug.

If you’re running your development environment behind an nginx proxy, you may run into some 502 Bad Gateway errors after enabling FirePHP.

[error] 103#0: *839 upstream sent too big header while reading response header from upstream

This happens because FirePHP’s output can get pretty large, and nginx by default tries to cap header output. The fix is simple, in your nginx.conf simply add the following lines:


proxy_buffer_size 16k;
proxy_buffers 4 16k;

You can bump up the header size (the last parameter) to whatever is required by your app to stop throwing errors.

The Brave New World of Server-Side Javascript

8 Jun

Not the B Team

Not the B Team

Every once in a while I hear whispers of server-side javascript and I get just as excited as the next person. But, I’ll admit that until recently a phrase like “Javascript on Rails” was on the same level as a phrase like “McGyver vs. The A Team – The Movie.” Fictonal. But awesome in theory.

(Don’t worry, they eventually join forces in the sequel)

But what about Jaxer?

My limited experience with server-side javascript (SSJ) has been through Jaxer, from Aptana.  It touts some cool functionality, like loading the DOM server-side and built-in database drivers for MySQL, with the former allowing for DOM manipulation and integration with libraries like jQuery.

The extremely original Gear logo

Ubiquitous "Gear" Logo

But, in its attempts to blur the lines between client and server execution, Jaxer has made sacrifices in its extensibility. It is meant to be plugged into another system. For instance, I don’t know of an easy way to expose data through a RESTful JSON/XML API (like so many sites are doing nowadays) using Jaxer alone.

What I’m really looking for in SSJ is something akin to the ecosystem surrounding languages like Ruby and Python.  That’s why I was pleasantly surprised to stumble accross a few projects that aim to do just that.

Narwhal – Javascript Standard Library and Interactive Console

The foundation of any good ecosystem is a standard library.  Enter Narwhal, “a flexible javascript standard library.”

There are a lot of things to like about this project, but the primary benefit is its attempts to play nice with multiple javascript runtimes like Rhino and V8cgi.  Also, this project is embracing Mozilla’s ServerJS standard which I think is important for its longevity and interoperability.

Setup is a breeze, you can simply clone the project from github:

git clone git://github.com/tlrobinson/narwhal.git

Once you add narwhal/bin to your $PATH, you can use the convenient symlink js to enter an interactive javascript console similar to irb or python.

Jack – Javascript’s “Rack”

Interestingly enough, Narwhal came into existence as it’s author, Tom Robinson, was working on Jack.

JSGI is a webserver interface for JavaScript inspired by Ruby’s Rack (http://rack.rubyforge.org/) and Python’s WSGI (http://www.wsgi.org/).

Jack is an implementation of JSGI compatible handlers (to connect to web servers), middleware (to intercept and manipulate requests to add functionality), and utilities (to make using JSGI easier).

Setup is also breezy. Simply clone Jack into the same directory you cloned Narwhal into:

git clone git://github.com/tlrobinson/jack.git

Since you’ve already added narwhal’s bin directory to your path, lets just make a symlink to jackup from there.

From your narwhal/bin directory:
ln -s [path/to/jack]/bin/jackup jackup

Run jackup -h for usage.

So, what’s next? Where’s Javascript on Rails?

With Narwhal and Jack, you can start writing basic web apps. Looking at the example.js script in jack/examples we can see the basic request/response structure. Looks familiar huh?

var Jack = require("jack");

var map = {};

// an extremely simple Jack application
map["/hello"] = function(env) {
    return [200, {"Content-Type":"text/plain"}, ["Hello from " + env["SCRIPT_NAME"]]];
}

// apply the URLMap
var app = Jack.ContentLength(Jack.URLMap(map));
//...

While these two pieces are a good start to a vibrant server-side javascript ecosystem, there’s still a long ways to go to before it’ll be on par with Ruby and Python.

What SSJ needs is its Django/Pylons/Rails/Merb. There are a couple of projects I’ve found in the wild that are using Jack and Narwhal, but they appear to still be in very rapid flux.

Nitro

Nitro provides a library of carefully designed middleware and utilities for creating scalable, standards-compliant Web Applications with JavaScript.

Helma NG

Helma NG consists of several components that can be used together or alone:

1) A compact JavaScript runtime environment based on Mozilla Rhino. It adds
to Rhino a reloading module system that is compatible to the ServerJS
Securable Module proposal.

2) An interactive shell with support for autocompletion and history.

3) A module library implemented in JavaScript, covering basic functionality
such as extensions to the built-in objects, file I/O, logging, persistence,
client and server side HTTP support and more.

Weekly Digest for June 4th

4 Jun

googlereader (feed #4)
Shared 2 links.
2:25pm via Google Reader
twitter (feed #3)
Interesting that Github:FI is a compiled JRuby app, does that mean no tweaking the source? – http://fi.github.com [#]
3:14pm via Twitter
twitter (feed #3)
also would be nice to have the gist.github app inside a private network – I’m assuming github:fi does not include gist? [#]
3:16pm via Twitter
delicious (feed #2)
5:38pm via Delicious
delicious (feed #2)
6:45pm via Delicious
blog (feed #1)
10:35pm via britg.com
twitter (feed #3)
Pan Seared Salmon with Mushroom Risotto and Baby Spinach Salad http://britg.com/?p=942 [#]
10:37pm via Twitter
delicious (feed #2)
10:46pm via Delicious
twitter (feed #3)
HAML in CakePHP – http://bit.ly/155oDX [#]
3:02am via Twitter
delicious (feed #2)
6:15pm via Delicious
twitter (feed #3)
I absolutely love the wordpress theme http://mixcss.com is using. Need to find a project to use it on. Theme is: http://bit.ly/vpQJ9 [#]
6:19pm via Twitter
delicious (feed #2)
8:22pm via Delicious
twitter (feed #3)
APE Project looks like Comet-made-easy – Ajax Push pluggable into Apache http://www.ape-project.org/en/about.html [#]
8:53pm via Twitter

Pan Seared Salmon with Mushroom Risotto and Baby Spinach Salad

2 Jun

Pan Seared Salmon with Mushroom Risotto

Pan Seared Salmon with Mushroom Risotto