Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multistore setup #27

Open
racke opened this issue Mar 12, 2014 · 17 comments
Open

Multistore setup #27

racke opened this issue Mar 12, 2014 · 17 comments
Assignees
Milestone

Comments

@racke
Copy link
Member

racke commented Mar 12, 2014

Add support for multiple stores to the schema. This is subject to research and discussion.

Regards
Racke

@racke racke self-assigned this Mar 12, 2014
@racke racke added this to the Multistore milestone Mar 12, 2014
@mrmaloof
Copy link

mrmaloof commented Dec 3, 2014

What may I do to help in here?

@hexfusion
Copy link
Contributor

I think we need to think about what multi-store is in the dancer world. Basically if the template is build with a solid theme-able CSS infrastructure. Once we move the pages to the DB you could in theory have a single database and single app do multistore. Schema would need some work because you can't define the same navigation route twice. I would also think about perhaps having a separate plackup per store. Just so you can restart one at a time and not force restart on all. Just ideas is what we need now on how this is going to work. I don't have a clear vision personally.

@mrmaloof
Copy link

mrmaloof commented Dec 3, 2014

What we've done in our schema in IC5 is add a 'storeid' column to tables like transactions, orderline, products, etc. Then we set IC variable STOREID for each catalog. We use the domain name of the site for the storeid value.

In Dancer world we don't have a notion of a catalog.cfg or a sub configuration. We could just glean the storeid from the request and set a $storeid variable in our app and then use it through out. I'm thinking one app for multiple stores. (I don't care about restarting since we only start when an instance is created view AWS autoscaling group.)

I'm messing around with "hook before_template_render" to set the view based on the site. So we may have something like....

app/views/bottlenose_product_1
app/views/bottlenose_product_2
www/storeid1.com/views
www/storeid2.com/views

Each site cold have a custom view or we could fallback on our predesigned templates.

@hexfusion
Copy link
Contributor

Try setting up a nginx and plackup multi-domain test on a basic dancer app. Then with your hook before_template_render get your host and put it into session.

# check if host exists
my $host = session 'host';

unless ( $host ) {
    # set host in session
    $host = session host => request->host;
}

if ( !$host eq  request->host ) {
    # something bad is going on maybe kill the session?
};

@mrmaloof
Copy link

mrmaloof commented Dec 4, 2014

Cool! Thanks Sam. I have something like that going but now I’m stuck on having a per site layouts/main.tt but a common index.tt. It seems like layouts is a special directory in views. I can specify a per site views location but then I’d have repeated index.tt files for each site. I need per site layouts but the other templates like index.tt or product_view.tt to be common. Any ideas on how to do that? And I know this has nothing to do with Schema. Sorry for talking about it here.

@hexfusion
Copy link
Contributor

Well I believe you can do something like this.

get '/' => sub {
    template 'home', { layout => 'site1' };
};

@racke
Copy link
Member Author

racke commented Dec 4, 2014

Actually it is the third parameter:

get '/' => sub {
    template 'home', { .....} , { layout => 'site1' };
};

@mrmaloof
Copy link

mrmaloof commented Dec 4, 2014

On Dec 4, 2014, at 9:04 AM, Stefan Hornburg (Racke) [email protected] wrote:

Actually it is the third parameter:

get '/' => sub {
template 'home', { .....} , { layout => 'site1' };
};
But doesn’t layouts have to be in views directory? So if I had a structure like so….

bottlenose/views/home.tt
bottlenose/views/layouts/main.tt
site1/views/layouts/site1.tt
site1/public

I’d like site1 to use its layout to display the common template home.tt.

I see where I could just put various layouts for different sites inside the bottlenose directory structure but can I do it the way I specified above where I have a “root directory” for each site where we would redefine or override the default settings from bottlenose?

http://www.bottlenose-wine.com/
Bill Carr, President at Bottlenose
(413) 584-0400
http://www.bottlenose-wine.com http://www.bottlenose-wine.com/
 Download vCard http://www.bottlenose-wine.com/vcard/BillCarr.vcf

@hexfusion
Copy link
Contributor

But then your multi app right?

@racke
Copy link
Member Author

racke commented Dec 4, 2014

Actually for multisite it would be really useful to have Dancer2 implementation :-/

@mrmaloof
Copy link

mrmaloof commented Dec 4, 2014

On Dec 4, 2014, at 10:05 AM, Stefan Hornburg (Racke) [email protected] wrote:

Actually for multisite it would be really useful to have Dancer2 implementation :-/

I’m using Dancer2

http://www.bottlenose-wine.com/
Bill Carr, President at Bottlenose
(413) 584-0400
http://www.bottlenose-wine.com http://www.bottlenose-wine.com/
 Download vCard http://www.bottlenose-wine.com/vcard/BillCarr.vcf

@hexfusion
Copy link
Contributor

Issue being that our IC6 plugin infrastructure is in Dancer1. I know work has begun on this for Dancer2 but ...

@SysPete
Copy link
Member

SysPete commented Dec 6, 2014

Adding Plack::Middleware::Static to your app.psgi would allow you to rewrite paths for things beneath /public. Here's a guess (nasty quick untested hack):

#!/usr/bin/env perl
use FindBin;
use lib "$FindBin::Bin/../lib";
use Dancer2;
use MyApp;
use Plack::Builder;

my @sites = (qw/ example.com banana.com /);
builder {
    enable "Plack::Middleware::Static",
      root => 'public/',
      path => sub {
        my ( $path_info, $env ) = @_;
        ( my $http_host = $env{HTTP_HOST} ) =~ s/:.+//;
        if ( my ($match) =
            grep { $_ eq $http_host || $_ =~ /\.${http_host}$/ } @sites )
        {
            s|(^/site/)|$1/$match/|;
            return 1;
        }
        else {
            return 0;
        }
      },
      pass_through => 1;
    dance;
};

For views handled by D2 you need to do magic in before_template hook.

@SysPete
Copy link
Member

SysPete commented Dec 6, 2014

You could also do static file rewrites in nginx/apache/...

@SysPete
Copy link
Member

SysPete commented Nov 24, 2015

This is currently being worked on in branch topic/multistore_gh27

@racke
Copy link
Member Author

racke commented Nov 24, 2015

👍

Excellent news!

@SysPete
Copy link
Member

SysPete commented Nov 26, 2015

This is progressing. It is now possible to deploy the new schema and populate stores with initial fixtures (countries, currencies, states, roles, ...). Now need to fix the huge pile of code I've broken getting this far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants