Skip to content

Plack multi app setup (TableEditor, IC6)

sbatschelet edited this page Nov 12, 2014 · 1 revision

Using TableEditor as the back-end for Interchange6 is like using ice cream with apple pie. This document is intended to give you the information nessisary to setup Plack in a multi-app environment.

example multi-app pgsi file

#!/usr/bin/env perl

use strict;
use warnings;

use Dancer ':syntax';
use Dancer::Handler;
use Plack::App::URLMap;

# list app libs
use lib '/home/sam/applications/DemoShop/lib';
use lib '/home/sam/applications/TableEditor/lib';

my $app1 = sub {
    my $appdir = '/home/sam/applications/DemoShop';
    local $ENV{DANCER_APPDIR} = $appdir;
    setting appdir => $appdir;
    setting environment => 'development';
    Dancer::Config->load;
    load_app "DemoShop";
    Dancer::App->set_running_app("DemoShop");
    my $env = shift;
    Dancer::Handler->init_request_headers($env);
    my $req = Dancer::Request->new(env => $env);
    Dancer->dance($req);
};

my $app2 = sub {
    my $appdir = '/home/sam/applications/TableEditor';
    local $ENV{DANCER_APPDIR} = $appdir;
    setting appdir => $appdir;
    setting environment => 'development';
    Dancer::Config->load;
    load_app "TableEdit";
    Dancer::App->set_running_app("TableEdit");
    my $env = shift;
    Dancer::Handler->init_request_headers($env);
    my $req = Dancer::Request->new(env => $env);
    Dancer->dance($req);
};

my $urlmap = Plack::App::URLMap->new;
$urlmap->map("/" => $app1);
$urlmap->map("/admin" => $app2);

my $app = $urlmap->to_app;

Note: Although the -E flag is used in plackup I still have to set setting environment => 'development'; for this to work correctly past the 1st app. Otherwise the config.yml was read but not environment/development.yml.