HTTP::Server::EV::ServeStatic - Simple static file server.
Simple static file server for HTTP::Server::EV. This module good for testing apps without frontend server. It's blocking and reads entire file into memory, so if you going to serve big files and need good performance - use frontend servers like nginx or lighttpd.
use HTTP::Server::EV; use HTTP::Server::EV::ServeStatic; my $static_server = HTTP::Server::EV::ServeStatic->new({ basedir => './html', indexes => [qw/index.html index.xhml default.html/], forbidden_ext => [qw/pm pl php conf ini/], rewrite_cb => sub { local($_) = @_; s/foo/bar/; # /path/foo/file.txt -> /path/bar/file.txt return $_; } }); # or defaults my $static_server = HTTP::Server::EV::ServeStatic->new; HTTP::Server::EV->new->listen( 8080 , sub{ my ($cgi) = @_; $static_server->serve($cgi); # try serve file. # or give control to your app if file not found $cgi->header({ STATUS => '404 Not Found' }); $cgi->print('404 - File not found'); }); EV::run;
Directory with files. Dafault './'
Files to search for if no file specified in url. Arrayref. Default [qw/index.html/]
Don't serve files with those extensions. Arrayref. Default [qw/pm pl/]
Callback for rewriting uri before processing request. Gets uri as first arg and need to return new uri.
Process request
To install HTTP::Server::EV::ServeStatic, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTTP::Server::EV::ServeStatic
CPAN shell
perl -MCPAN -e shell install HTTP::Server::EV::ServeStatic
For more information on module installation, please visit the detailed CPAN module installation guide.