Have you checked http://localhost:5000/api/api/userdata/dancer_operator?
On 14 July 2016 at 14:37, James E Keenan <[email protected]> wrote: > On 07/12/2016 10:44 AM, Warren Young wrote: > >> On Jul 10, 2016, at 11:20 AM, James E Keenan <[email protected]> wrote: >> >>> >>> All the endpoints defined in lib/mywebapp.pm continue to function as >>> expected. But the endpoint, /api/userdata/:user, defined in lib/mywebapp/ >>> api.pm, no longer works. >>> >> >> That’s because your “mount” for the api.pm routes prepends ‘/api’ to >> them. When you use the module standalone as you’re attempting to now, that >> bit is stripped off. You’ll find that you now have /userdata/$stuff now. >> >> Easy fix: wrap the route definitions in api.pm in a prefix block: >> >> prefix '/api' => sub { >> any ['get', 'post'] => '/userdata/:user' => sub { >> # etc >> }; >> }; >> >> > Thank you for your reply. However, when I wrap the endpoint in > mywebapp::api with 'prefix' per your suggestion, I am still getting 404s on > both 'http://localhost:5000/api/userdata/dancer_operator' and ' > http://localhost:5000/userdata/dancer_operator'. > > Here is the diff of what I am trying: > > ##### > diff --git a/bin/app.psgi b/bin/app.psgi > index 46d8845..e9ac3da 100755 > --- a/bin/app.psgi > +++ b/bin/app.psgi > @@ -6,11 +6,12 @@ use FindBin; > use lib "$FindBin::Bin/../lib"; > > use mywebapp; > -use mywebapp::api; > -use Plack::Builder; > - > -builder { > - mount '/' => mywebapp->to_app; > - mount '/api' => mywebapp::api->to_app; > -}; > +#use mywebapp::api; > +#use Plack::Builder; > +# > +#builder { > +# mount '/' => mywebapp->to_app; > +# mount '/api' => mywebapp::api->to_app; > +#}; > +mywebapp->to_app; > > diff --git a/lib/mywebapp.pm b/lib/mywebapp.pm > index 997bdc7..7c940da 100644 > --- a/lib/mywebapp.pm > +++ b/lib/mywebapp.pm > @@ -1,6 +1,6 @@ > package mywebapp; > use v5.10.1; > -use Dancer2; > +use Dancer2 appname => mywebapp; > use Dancer2::Plugin::Database; > use Crypt::SaltedHash; > use Data::Dump; > diff --git a/lib/mywebapp/api.pm b/lib/mywebapp/api.pm > index 3af1adf..88b47f7 100644 > --- a/lib/mywebapp/api.pm > +++ b/lib/mywebapp/api.pm > @@ -1,6 +1,6 @@ > package mywebapp::api; > use v5.10.1; > -use Dancer2; > +use Dancer2 appname => mywebapp; > use Dancer2::Plugin::Database; > use Crypt::SaltedHash; > use Data::Dump; > @@ -13,6 +13,7 @@ set session => 'Simple'; > set views => path( app->location, "templates" ); > set serializer => 'JSON'; > > +prefix '/api' => sub { > any ['get', 'post'] => '/userdata/:user' => sub { > > my $user_value = route_parameters->get('user'); > @@ -34,6 +35,7 @@ any ['get', 'post'] => '/userdata/:user' => sub { > } > } > }; > +}; > > start; > ###### > > So I'm still finding that 'appname' is not DWIMming. > > Thank you very much. > Jim Keenan > _______________________________________________ > dancer-users mailing list > [email protected] > http://lists.preshweb.co.uk/mailman/listinfo/dancer-users >
_______________________________________________ dancer-users mailing list [email protected] http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
