-
I have an application which serves several domains. Each incoming request may be for a different than the previous domain. So far I implemented in sub _around_dispatch ($next, $c) {
# ...
state $s_paths = $app->static->paths;
state $r_paths = $app->renderer->paths;
#...complex logic here
unshift @{$s_paths}, "$root/$dom->{domain}/public";
unshift @{$r_paths}, "$root/$dom->{domain}/templates";
$next->();
shift @{$s_paths};
shift @{$r_paths};
} But templates from different paths have the same names and Mojolicious::Renderer does not differentiate the cached templates by name.
How to set the template name so for |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
This works for now, but only in CGI mode when the templates are not cached. |
Beta Was this translation helpful? Give feedback.
-
You can disable the template cache if you wish, see https://stackoverflow.com/a/41751645/5848200. This of course can be a significant performance impact as every request will have to read templates from disk. Perhaps it would be a more efficient (and cacheable) setup to have the domains as subdirectories within the template path, prepended at the time of selecting the template. |
Beta Was this translation helpful? Give feedback.
-
Another more common idea is just to run multiple instances of the app - using Toadfarm or your reverse proxy to dispatch to the correct app based on domain, and having the template/static dirs read from config for each instance. |
Beta Was this translation helpful? Give feedback.
Another more common idea is just to run multiple instances of the app - using Toadfarm or your reverse proxy to dispatch to the correct app based on domain, and having the template/static dirs read from config for each instance.