[dancer-users] Dancer2::Manual: confused as to use of 'appname' keyword to distribute code across packages
Warren Young
wyml at etr-usa.com
Tue Jul 12 15:44:42 BST 2016
On Jul 10, 2016, at 11:20 AM, James E Keenan <jkeen at verizon.net> 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
};
};
You could even extract the other layer, too:
prefix '/api' => sub {
prefix '/userdata' => sub {
any ['get', 'post'] => ':user' => sub {
# etc
};
};
};
More information about the dancer-users
mailing list