[dancer-users] Multiple apps with Plack and Apache
Chad Wallace
cwallace at lodgingcompany.com
Tue Jul 12 21:21:35 BST 2016
On Tue, 12 Jul 2016 19:55:31 +0100
janet davis <oscarjwoofer at gmail.com> wrote:
> Hi there,
>
> I have a web server running Apache with a single vhost that serves a
> lot of Perl cgi scripts from cgi-bin.
>
> I've been trying out Dancer, which I really like, but I can't figure
> out the best way to deploy apps in my Apache environment. I want to
> keep my Apache cgi configuration to serve legacy scripts but I want
> to start building new projects based on psgi in something like Dancer.
>
> I want Apache to use www.myserver/cgi-bin/appname/script.pl for old
> code (which currently works) and www.myserver/app1 for newer Dancer
> based apps. Please don't think I'm being lazy by asking, I have read
> the documentation and looked at the example for deploying multiple
> apps via fcgi but I am still confused as I have limited experience
> with Apache - I am working on that. What's the best way to set this
> up, bearing in mind that I may want to run say 10-15 Dancer apps from
> my server alongside my cgi-scripts? Do I have to set up a vhost for
> each app? I have Apache::Plack::Handler but I'm not sure whether I
> should be using Plack::Builder to mount my apps (which is mentioned
> in an older Dancer Cookbook, but not the current deployment guide.
> Can someone help me get on the right track please?
I'm not sure it matches what you currently have in mind, but what I
would do is set up www.myserver/app1 with mod_proxy to a standalone
Plack/Dancer process for the app. You would need something like this
in your VirtualHost for each app:
ProxyPass /app1 http://localhost:5000/app1
You'd also have to manage starting, stopping and reloading each of your
apps on its own, with a dedicated port, like 5000 in the line above.
If you wanted to combine your apps into one, you can do that with
Plack::Builder in a single app.psgi script. Then you get the benefit
of only having one script to start and stop, and one port. I currently
do that with one of my apps to separate the AJAX-specific stuff, based
on code I found in Dancer2::Cookbook[1]:
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../lib";
use Plack::Builder;
use newtlc;
use newtlc::API;
builder {
mount '/' => newtlc->to_app;
mount '/api' => newtlc::API->to_app;
};
[1]
https://metacpan.org/pod/distribution/Dancer2/lib/Dancer2/Cookbook.pod#App-specific-feature
--
C. Chad Wallace, B.Sc.
The Lodging Company
http://www.lodgingcompany.com/
OpenPGP Public Key ID: 0x262208A0
More information about the dancer-users
mailing list