Skip to content

Commit

Permalink
Item13897: Added support for serving static files.
Browse files Browse the repository at this point in the history
Uses Plack::Middleware::Static.

- Added guessing of the root directory using %INC when no FOSWIKI_HOME
defined.
  • Loading branch information
vrurg committed Sep 19, 2016
1 parent f4d4dbc commit d5fa688
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
24 changes: 23 additions & 1 deletion core/bin/foswiki.psgi
@@ -1,12 +1,34 @@
#!/usr/bin/env perl
# See bottom of file for license and copyright information
use v5.14;
use Cwd;
use lib Cwd::abs_path("../lib");
use File::Spec;

my $root = $ENV{FOSWIKI_HOME};
if ( !$root ) {
# Try to guess our root dir by looking into %INC
my $incKey = ( grep { /\/foswiki.*\.psgi$/ } keys %INC )[0];
my $scriptFile = $INC{$incKey};
my ( $volume, $scriptDir ) = File::Spec->splitpath($scriptFile);
$root =
File::Spec->catpath( $volume,
File::Spec->catdir( $scriptDir, File::Spec->updir ), "" );
}

use lib Cwd::abs_path( File::Spec->catdir( $root, "lib" ) );
use Plack::Builder;
use Foswiki::App;

my $app = sub {
return Foswiki::App->run( env => shift, );
};

builder {
enable 'Plack::Middleware::Static',
path => qr/^\/pub\//,
root => $root;
$app;
}
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Expand Down
31 changes: 26 additions & 5 deletions core/bin/foswiki_debug.psgi
@@ -1,8 +1,22 @@
#!/usr/bin/env perl
# See bottom of file for license and copyright information
use Cwd;
use lib Cwd::abs_path("../lib"),
( $ENV{FOSWIKI_HOME} ? $ENV{FOSWIKI_HOME} . "/lib" : () );
use File::Spec;

my $root = $ENV{FOSWIKI_HOME};
if ( !$root ) {

# Try to guess our root dir by looking into %INC
my $incKey = ( grep { /\/foswiki.*\.psgi$/ } keys %INC )[0];
my $scriptFile = $INC{$incKey};
my ( $volume, $scriptDir ) = File::Spec->splitpath($scriptFile);
$root =
File::Spec->catpath( $volume,
File::Spec->catdir( $scriptDir, File::Spec->updir ), "" );
}

use lib Cwd::abs_path( File::Spec->catdir( $root, "lib" ) );
use Plack::Builder;
use Foswiki::App;
use HTTP::Server::PSGI;

Expand All @@ -19,9 +33,9 @@ BEGIN {

my $app = sub {
my $env = shift;

Devel::Leak::Object::checkpoint if CHECKLEAK;

my $rc = Foswiki::App->run( env => $env, );

if (CHECKLEAK) {
Expand All @@ -42,7 +56,14 @@ my $server = HTTP::Server::PSGI->new(
timeout => 120,
);

$server->run($app);
$server->run(
builder {
enable 'Plack::Middleware::Static',
path => qr/^\/pub\//,
root => $root;
$app;
}
);
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Expand Down

0 comments on commit d5fa688

Please sign in to comment.