NAME

HTTP::Engine::Middleware::Static - handler for static files

SYNOPSIS

my $mw = HTTP::Engine::Middleware->new;
$mw->install( 'HTTP::Engine::Middleware::Static' => {
    regexp  => qr{^/(robots.txt|favicon.ico|(?:css|js|img)/.+)$},
    docroot => '/path/to/htdocs/',
});
HTTP::Engine->new(
    interface => {
        module => 'YourFavoriteInterfaceHere',
        request_handler => $mw->handler( \&handler ),
    }
)->run();

# $ GET http//localhost/css/foo.css
# to get the /path/to/htdocs/css/foo.css

# $ GET http//localhost/js/jquery.js
# to get the /path/to/htdocs/js/jquery.js

# $ GET http//localhost/robots.txt
# to get the /path/to/htdocs/robots.txt

has multi document root

my $mw = HTTP::Engine::Middleware->new;
$mw->install(
    'HTTP::Engine::Middleware::Static' => {
        regexp  => qr{^/(robots.txt|favicon.ico|(?:css|js|img)/.+)$},
        docroot => '/path/to/htdocs/',
    },
    'HTTP::Engine::Middleware::Static' => {
        regexp  => qr{^/foo(/.+)$},
        docroot => '/foo/bar/',
    },
);
HTTP::Engine->new(
    interface => {
        module => 'YourFavoriteInterfaceHere',
        request_handler => $mw->handler( \&handler ),
    }
)->run();

# $ GET http//localhost/css/foo.css
# to get the /path/to/htdocs/css/foo.css

# $ GET http//localhost/robots.txt
# to get the /path/to/htdocs/robots.txt

# $ GET http//localhost/foo/baz.html
# to get the /foo/bar/baz.txt

through only the specific URL to backend

my $mw = HTTP::Engine::Middleware->new;
$mw->install( 'HTTP::Engine::Middleware::Static' => {
    regexp  => qr{^/(robots.txt|favicon.ico|(?:css|img)/.+|js/(?!dynamic).+)$},
    docroot => '/path/to/htdocs/',
});
HTTP::Engine->new(
    interface => {
        module => 'YourFavoriteInterfaceHere',
        request_handler => $mw->handler( \&handler ),
    }
)->run();

# $ GET http//localhost/js/jquery.js
# to get the /path/to/htdocs/js/jquery.js

# $ GET http//localhost/js/dynamic-json.js
# to get the your application response

Will you want to set config from yaml?

my $mw = HTTP::Engine::Middleware->new;
$mw->install( 'HTTP::Engine::Middleware::Static' => {
    regexp  => '^/(robots.txt|favicon.ico|(?:css|img)/.+|js/(?!dynamic).+)$',
    docroot => '/path/to/htdocs/',
});
HTTP::Engine->new(
    interface => {
        module => 'YourFavoriteInterfaceHere',
        request_handler => $mw->handler( \&handler ),
    }
)->run();

# $ GET http//localhost/js/jquery.js
# to get the /path/to/htdocs/js/jquery.js

# $ GET http//localhost/js/dynamic-json.js
# to get the your application response

DESCRIPTION

On development site, you would feed some static contents from Interface::ServerSimple, or other stuff. This module helps that.

AUTHORS

Kazuhiro Osawa