From f670031d9800414d5c7f1372e3231e379f3ab2cd Mon Sep 17 00:00:00 2001 From: Ed J Date: Wed, 7 Nov 2018 05:57:50 +0000 Subject: [PATCH 1/2] de-hardcode "/yancy" in 404 template, make configurable --- lib/Mojolicious/Plugin/Yancy.pm | 28 ++++++++++++++++++++-------- lib/Yancy.pm | 2 +- lib/Yancy/Help/Config.pod | 17 +++++++++++++++++ t/api.t | 9 +++++++++ t/plugin/auth/basic.t | 2 +- t/standalone.t | 15 +++++++++++++++ 6 files changed, 63 insertions(+), 10 deletions(-) diff --git a/lib/Mojolicious/Plugin/Yancy.pm b/lib/Mojolicious/Plugin/Yancy.pm index ccac6da6..8021914a 100644 --- a/lib/Mojolicious/Plugin/Yancy.pm +++ b/lib/Mojolicious/Plugin/Yancy.pm @@ -54,12 +54,21 @@ connections. helper pg => sub { state $pg = Mojo::Pg->new( 'postgres:///myapp' ) }; plugin Yancy => { backend => { Pg => app->pg } }; +=item editor + +Configuration for the Yancy web application. A hash, permitting these +keys: + +=over + =item route A base route to add Yancy to. This allows you to customize the URL -and add authentication or authorization. Defaults to allowing access -to the Yancy web application under C, and the REST API under -C. +and add authentication or authorization. If a string is supplied, it +will be turned into a L object with that +path, under the app. Defaults to C. + +=back =item return_to @@ -410,8 +419,11 @@ has _filters => sub { {} }; sub register { my ( $self, $app, $config ) = @_; - my $route = $config->{route} // $app->routes->any( '/yancy' ); - $route->to( return_to => $config->{return_to} // '/' ); + my $editor_route = $config->{editor}{route} // '/yancy'; + $editor_route = $app->routes->any( $editor_route ) + if !UNIVERSAL::isa( $editor_route, 'Mojolicious::Routes::Route' ); + $editor_route->to( return_to => $config->{return_to} // '/' ); + my $api_route = $editor_route->any( '/api' )->name( 'yancy.api' ); $config->{api_controller} //= 'Yancy::API'; $config->{openapi} = _ensure_json_data( $app, $config->{openapi} ); @@ -423,7 +435,7 @@ sub register { # Helpers $app->helper( 'yancy.config' => sub { return $config } ); - $app->helper( 'yancy.route' => sub { return $route } ); + $app->helper( 'yancy.route' => sub { return $editor_route } ); $app->helper( 'yancy.backend' => sub { state $backend = load_backend( $config->{backend}, $config->{collections} || $config->{openapi}{definitions} ); } ); @@ -444,7 +456,7 @@ sub register { $app->helper( 'yancy.filter.apply' => curry( \&_helper_filter_apply, $self ) ); # Routes - $route->get( '/' )->name( 'yancy.index' ) + $editor_route->get( '/' )->name( 'yancy.index' ) ->to( template => 'yancy/index', controller => $config->{api_controller}, @@ -497,7 +509,7 @@ sub register { $self->_openapi_spec_add_mojo( $spec, $config ); my $openapi = $app->plugin( OpenAPI => { - route => $route->any( '/api' )->name( 'yancy.api' ), + route => $api_route, spec => $spec, default_response_name => '_Error', } ); diff --git a/lib/Yancy.pm b/lib/Yancy.pm index cd1966da..56eb4096 100644 --- a/lib/Yancy.pm +++ b/lib/Yancy.pm @@ -190,7 +190,7 @@ __DATA__

This is the default not found page.

Getting Started

-

To edit your data, go to /yancy.

+

To edit your data, go to <%== url_for 'yancy.index' %>.

Add your templates to <%= app->home->child( 'templates' ) %>. Each template becomes a URL in your site: