getting the routes info for `load_app` loaded apps
I have written a plugin (modeled after Dancer::Plugin::SiteMap) that allows me to create a few standard routes that are available in all applications. For example, by adding my plugin (I call it Dancer::Plugin::Meta), my applications automatically get a route called http://server/app/meta/author which returns the author information set in the config file. This works rather well, and has become a key part of the app (there are other fairly useful routes besides author that get added, such as license, version, and most importantly, a listing of all the routes much like the SiteMap). Now I have an application where sub-applications are loaded using load_app 'app1', prefix -> '/app1'; load_app 'app2', prefix -> '/app2'; This also works rather well, except now my plugin doesn't work. My base app is reachable at `http://server/baseapp` so the following URI works `http://server/baseapp/meta/author` but `http://server/baseapp/app1/meta/author` doesn't work... I get the void. Additionally, while `http://server/baseapp/meta/author` works, `http://server/baseapp/meta/resources` does not work. Normally, /meta/resources returns a listing of all the resources, but now I get the following error "Serializer (Dancer::Serializer::JSON) failed at serializing HASH(0x7f9ae4696f00):\nencountered object '(?^:^\\/baseapp(?:\\/)?$)', but neither allow_blessed nor convert_blessed settings are enabled at /opt/local/lib/perl5/site_perl/5.14.1/JSON.pm line 154.\n" Would appreciate any guidance on how to retrieve all the URIs for the app loaded using load_app and resolving the above errors. -- Puneet Kishor
On Dec 2, 2011, at 9:01 AM, Puneet Kishor wrote:
I have written a plugin (modeled after Dancer::Plugin::SiteMap) that allows me to create a few standard routes that are available in all applications. For example, by adding my plugin (I call it Dancer::Plugin::Meta), my applications automatically get a route called http://server/app/meta/author which returns the author information set in the config file.
This works rather well, and has become a key part of the app (there are other fairly useful routes besides author that get added, such as license, version, and most importantly, a listing of all the routes much like the SiteMap).
Now I have an application where sub-applications are loaded using
load_app 'app1', prefix -> '/app1'; load_app 'app2', prefix -> '/app2';
This also works rather well, except now my plugin doesn't work. My base app is reachable at `http://server/baseapp` so the following URI works `http://server/baseapp/meta/author` but `http://server/baseapp/app1/meta/author` doesn't work... I get the void.
Additionally, while `http://server/baseapp/meta/author` works, `http://server/baseapp/meta/resources` does not work. Normally, /meta/resources returns a listing of all the resources, but now I get the following error
"Serializer (Dancer::Serializer::JSON) failed at serializing HASH(0x7f9ae4696f00):\nencountered object '(?^:^\\/baseapp(?:\\/)?$)', but neither allow_blessed nor convert_blessed settings are enabled at /opt/local/lib/perl5/site_perl/5.14.1/JSON.pm line 154.\n"
solved the above problem. Now, I am able to get *all* the resources when I go to `http://server/basemap/meta/resource` but I reach the void when I go to `http://server/basemap/app1/meta/resource`. Ideally, I would like to go to a particular sub app and have the meta routes available at the sub apps. -- Puneet Kishor
On 02/12/11 15:01, Puneet Kishor wrote:
I have written a plugin (modeled after Dancer::Plugin::SiteMap) that [snip] Now I have an application where sub-applications are loaded using
load_app 'app1', prefix -> '/app1'; load_app 'app2', prefix -> '/app2';
This also works rather well, except now my plugin doesn't work. My base app is reachable at `http://server/baseapp` so the following URI works `http://server/baseapp/meta/author` but `http://server/baseapp/app1/meta/author` doesn't work... I get the void.
If you have "get" calls as in Plugin::Sitemap then they'll get evaluated once, when the plugin gets loaded so it's not going to know anything about your sub-apps. So - I would put them in a "register_routes" sub, and make sure that gets called when the plugin gets loaded. I'd also add an optional parameter that lets you set up a custom prefix. Then, you can call register_routes to set up your meta routes for each sub-app. I'm not sure where you get information like "author" from, but that process might need some tweaks too if it can be different for each app. -- Richard Huxton Archonet Ltd
participants (2)
-
Puneet Kishor -
Richard Huxton