Last active
February 9, 2016 06:27
-
-
Save edipretoro/9512615afd84af0018a1 to your computer and use it in GitHub Desktop.
Tiny tool to create a webserver and serve my presentations created with Reveal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Plack::Builder; | |
use Plack::App::Directory; | |
use Cwd; | |
my $revealjs_repository = '/Users/manu/projets/reveal.js'; | |
my $main_app; | |
if (-e 'index.html') { | |
$main_app = Plack::App::IndexFile->new({ root => getcwd })->to_app; | |
} else { | |
$main_app = Plack::App::Directory->new({ root => getcwd })->to_app; | |
} | |
my $reveal_app = Plack::App::Directory->new({ root => $revealjs_repository })->to_app; | |
my $root = builder { | |
mount '/reveal.js' => $reveal_app; | |
mount '/' => $main_app; | |
}; | |
unless (caller) { | |
require Plack::Runner; | |
my $runner = Plack::Runner->new( server => 'Starlet' ); | |
$runner->parse_options( @ARGV ); | |
$runner->set_options( port => 8787 ); | |
return $runner->run( $root ); | |
} | |
return $root; | |
package Plack::App::IndexFile; | |
use parent 'Plack::App::File'; | |
sub locate_file | |
{ | |
my ($self, $env) = @_; | |
my $path = $env->{PATH_INFO} || ''; | |
return $self->SUPER::locate_file( $env ) unless $path && $path =~ m{/$}; | |
$env->{PATH_INFO} .= 'index.html'; | |
return $self->SUPER::locate_file( $env ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment