Index: trunk/BookmarkApp.pm
===================================================================
--- trunk/BookmarkApp.pm	(revision 52)
+++ trunk/BookmarkApp.pm	(revision 53)
@@ -24,9 +24,7 @@
     }]);
 
-    my $base_uri = URI->new;
-    $base_uri->scheme('http');
-    $base_uri->host($ENV{SERVER_NAME});
-    $base_uri->port($ENV{SERVER_PORT});
-    $base_uri->path($ENV{SCRIPT_NAME});
+    my $url = $self->query->url;
+    $url .= '/' unless $url =~ m{/$};
+    my $base_uri = URI->new($url);
 
     my $bookmarks = Bookmarks->new({
@@ -441,5 +439,5 @@
         $bookmark->uri($q->param('uri'));
         $bookmark->title($q->param('title'));
-        $bookmark->tags([ split(' ', $q->param('tags')) ]);
+        $bookmark->tags([ split ' ', $q->param('tags') || '' ]);
 
         # write to the database
Index: trunk/BookmarkApp/Dispatch.pm
===================================================================
--- trunk/BookmarkApp/Dispatch.pm	(revision 52)
+++ trunk/BookmarkApp/Dispatch.pm	(revision 53)
@@ -3,5 +3,5 @@
 
 package BookmarkApp::Dispatch;
-use base 'CGI::Application::Dispatch';
+use base 'CGI::Application::Dispatch::PSGI';
 
 sub dispatch_args {
Index: trunk/app.psgi
===================================================================
--- trunk/app.psgi	(revision 53)
+++ trunk/app.psgi	(revision 53)
@@ -0,0 +1,27 @@
+#!/usr/bin/perl -w
+use strict;
+
+use YAML;
+use Plack::Builder;
+
+use BookmarkApp::Dispatch;
+
+-e 'conf.yml' or die "Missing required conf.yml config file\n";
+
+my $config = YAML::LoadFile('conf.yml');
+my $app = BookmarkApp::Dispatch->as_psgi(
+    args_to_new => {
+        PARAMS => { dbname => $config->{dbname} },
+    },
+);
+
+builder {
+    enable_if { $_[0]->{REMOTE_ADDR} eq $config->{proxy_ip} } 'ReverseProxy';
+    enable_if { $_[0]->{REQUEST_METHOD} ne 'GET' } 'Auth::Digest', (
+        realm           => 'Bookmarks',
+        secret          => 'blahblahblah', #TODO: change this!
+        password_hashed => 1,
+        authenticator   => sub { $config->{digest_password} }
+    );
+    $app;
+};
