+ my $ANGULAR_JS = $ENV{ANGULAR_JS} || ( -e 'public/angular/build/angular.js' ? '/angular/build/angular.js' : '/angular/src/angular-bootstrap.js' );
+ warn "# $ANGULAR_JS";
+ $self->render_static( $ANGULAR_JS );
+};
+
+# CouchDB proxy for _design _view
+
+get '/:database/_design/:design/_view/:view' => sub {
+ my $self = shift;
+ my $url = join('/', $self->param('database'),'_design',$self->param('design'),'_view',$self->param('view') );
+ my $param = $self->req->url->query->clone->remove('callback')->to_string;
+ $url .= '?' . $param if $param;
+ warn "CouchDB proxy $url";
+ _render_jsonp( $self, _couchdb_get($url));
+};
+
+# static JSON files from public/json/database/entity/json
+
+get '/json' => sub {
+ _render_jsonp( shift, [ map { s{public/json/}{}; $_ } glob 'public/json/*' ] );
+};
+
+get '/json/:database' => sub {
+ my $self = shift;
+ my $database = $self->param('database');
+
+ my $status = {
+ document_counts => 0,
+ name => $database,
+ };
+
+ foreach my $path ( glob "public/json/$database/*" ) {
+ my @entities = glob "$path/*";
+ $path =~ s{public/json/$database/}{};
+ $status->{entities}->{$path} = scalar @entities;
+ $status->{document_counts}++;
+ }
+
+ _render_jsonp( $self, $status );