Index: trunk/BookmarkApp.pm
===================================================================
--- trunk/BookmarkApp.pm	(revision 40)
+++ trunk/BookmarkApp.pm	(revision 41)
@@ -11,6 +11,4 @@
 use Bookmarks;
 use URI;
-
-my $dbname = 'fk.db';
 
 sub setup {
@@ -24,12 +22,13 @@
         edit
     }]);
+
     my $base_uri = URI->new;
     $base_uri->scheme('http');
-    $base_uri->host($ENV{HTTP_X_FORWARDED_HOST} || $ENV{SERVER_NAME});
+    $base_uri->host($ENV{SERVER_NAME});
     $base_uri->port($ENV{SERVER_PORT});
     $base_uri->path($ENV{SCRIPT_NAME} . '/');
 
     my $bookmarks = Bookmarks->new({
-        dbname   => $dbname,
+        dbname   => $self->param('dbname'),
         base_uri => $base_uri,
     });
Index: trunk/index.cgi
===================================================================
--- trunk/index.cgi	(revision 40)
+++ trunk/index.cgi	(revision 41)
@@ -19,3 +19,12 @@
 
 package main;
-BookmarkApp::Dispatch->dispatch();
+# check for whether we are behind a reverse proxy, and adjust the SERVER_NAME accordingly
+# TODO: use something like Plack::Middlware::ReverseProxy instead
+$ENV{SERVER_NAME} = $ENV{HTTP_X_FORWARDED_HOST} if $ENV{HTTP_X_FORWARDED_HOST};
+
+BookmarkApp::Dispatch->dispatch(
+    args_to_new => {
+        #TODO: dbname should be in a config file
+        PARAMS => { dbname => 'fk.db' },
+    }
+);
