Skip to content

Instantly share code, notes, and snippets.

@edipretoro
Last active February 9, 2016 06:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edipretoro/9512615afd84af0018a1 to your computer and use it in GitHub Desktop.
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
#!/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