Skip to content

Commit

Permalink
Merge pull request #2 from tobyink/miniweb
Browse files Browse the repository at this point in the history
Add -Miniweb shortcut
  • Loading branch information
briandfoy committed Apr 3, 2023
2 parents 7436843 + 0ed64d7 commit 2458146
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/Mojolicious/Plugin/DirectoryServer.pm
Expand Up @@ -195,10 +195,14 @@ Mojolicious::Plugin::DirectoryServer - Serve static files from document root wit
}
})->start;
or
or
> perl -Mojo -E 'a->plugin("Directory", root => "/path/to/htdocs")->start' daemon
or
> perl -Miniweb
=head1 DESCRIPTION
L<Mojolicious::Plugin::Directory> is a static file server with a
Expand Down Expand Up @@ -295,7 +299,7 @@ Many thanks to the contributors for their work.
=head1 SEE ALSO
L<Plack::App::Directory>
L<Plack::App::Directory>, L<iniweb>.
=head1 LICENSE
Expand Down
63 changes: 63 additions & 0 deletions lib/iniweb.pm
@@ -0,0 +1,63 @@
package iniweb;

use feature ':5.16';
use ojo;

sub import {
$ENV{PERL_MINIWEB_ROOT} //= '.';
$ENV{PERL_MINIWEB_DIR_INDEX} //= 'index.html:index.htm';

local @ARGV = 'daemon';
my %opts = (
root => $ENV{PERL_MINIWEB_ROOT},
dir_index => [ split ':', $ENV{PERL_MINIWEB_DIR_INDEX} ],
);
a->plugin( DirectoryServer => %opts )->start;

exit( 0 );
}

1;

=head1 NAME
iniweb - Very quickly spawn a web server
=head1 SYNOPSIS
perl -Miniweb
=head1 DESCRIPTION
The command in the synopsis will spawn a web server, serving static files
from the current working directory.
=head2 Environment Variables
=over
=item C<PERL_MINIWEB_ROOT>
Root directory to serve. Defaults to the current directory.
=item C<PERL_MINIWEB_DIR_INDEX>
Colon-seperated list of filenames to treat as a directory index. Defaults to
C<< "index.html:index.htm" >>.
=back
=head1 AUTHOR
Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
=head1 SEE ALSO
L<Mojolicious::Plugin::DirectoryServer>
=head1 LICENSE
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut

0 comments on commit 2458146

Please sign in to comment.