Saturday, May 26, 2012

Run Dart in Apache web server

Posted by Seth Ladd

Today, Sam McCall announced mod_dart: the ability to run Dart apps embedded in Apache! Just like PHP, Perl, Python, and many other scripting languages, you can now use Dart to power your server-side web apps from inside the Apache web server.

From Sam's post:

I embedded the Dart VM in an Apache module, which allows it to host web applications written in Dart.
Install mod_dart, and drop this hello.dart file in your web server directory:

  #import('dart:apache');
  main() {
    response.headers.set('Content-Type', 'text/html');
    response.outputStream.writeString('<h1>Hello, dart!</h1>');
  }

What happens?
Every time someone visits /hello.dart, main() is called within a new isolate.
The dart:apache library provides access to the HttpRequest and HttpResponse objects, which are like in dart:io (except the input/output streams are synchronous).
You can add entries in httpd.conf to snapshot your scripts on startup, which makes them load much faster (until you edit them).

How to install?
It's a bit tricky at the moment, and involves building Dart from source (I hope to have binaries soon).
See the readme for details. (Describes mac/linux, I have no idea about windows...)
Note: I wouldn't put this on a public host for now, there are probably bugs!

Let me know if it's interesting, buggy, or broken!
Cheers,
Sam


Join the mailing list discussion and give it a shot!