Showing posts with label plack. Show all posts
Showing posts with label plack. Show all posts

Monday, April 4, 2016

Multi-site aware PSGI application development

Leave a Comment

The Plack::Builder allows mount multiple hosts, e.g. something as the following snippet:

my @sites = load_site_names(); my $apps; for my $site (@sites) {     $apps->{$site} = Some::PsgiFramework::MyApp->new( config => get_config($site) ); }  use Plack::Builder; builder {     for my $site (@sites) {         mount "$site" => $apps->{$site};     }     mount '/' => sub { ... }; } 

e.g.

  • the load_site_names returns a list of sites like http://example.com , http://some.other.site.com, ...
  • every "virtual-host" will use the same Some::PsgiFramework::MyApp
  • just their config is different

I need exactly the above - need develop one simple web-app which should be deployed for hunderts of different (low-traffic) sites and don't want setup an different PSGI server for each site.

However, the author of the Plack itself says (in the Plack::Request)

Note that this module is intended to be used by Plack middleware developers and web application framework developers rather than application developers (end users).

Writing your web application directly using Plack::Request is certainly possible but not recommended: it's like doing so with mod_perl's Apache::Request: yet too low level.

If you're writing a web application, not a framework, then you're encouraged to use one of the web application frameworks that support PSGI (http://plackperl.org/#frameworks), or see modules like HTTP::Engine to provide higher level Request and Response API on top of PSGI.

And this is the problem.

I checked many of different PSGI based frameworks in the MetaCPAN. And AFAIK each is singleton based, e.g. doesn't allows write applications which could be shared (mounted) many times for different sites in the same app.psgi.

So the questions are:

  • missed I something in the MetaCPAN (or in the docs), and here exists any (lighweight) web-framework which allows develop applications mountable many times in the app.psgi?
  • or i'm forced to develop Just Another My Own PSGI Framework? (To be honest, I not checked the catalyst - as it is too heavy-weight)
  • or just badly understand the "mounting"?

0 Answers

Read More