GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
HTTP::Engine::Middleware::Static(3) User Contributed Perl Documentation HTTP::Engine::Middleware::Static(3)
 

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

    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
Do you want 404 handle has backend application?
    my $mw = HTTP::Engine::Middleware->new;
    $mw->install( 'HTTP::Engine::Middleware::Static' => {
        regexp         => qr{^/css/.+)$},
        docroot        => '/path/to/htdocs/',
        is_404_handler => 0, # 404 handling off
    });
    HTTP::Engine->new(
        interface => {
            module => 'YourFavoriteInterfaceHere',
            request_handler => $mw->handler(sub {
                HTTP::Engine::Response->new( body => 'dynamic daikuma' );
            }),
        }
    )->run();
    # if css has foo.css file only
    # $ GET http//localhost/css/foo.css
    # to get the /path/to/htdocs/css/foo.css
    # $ GET http//localhost/css/bar.css
    # to get the 'dynamic daikuma' strings

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

Kazuhiro Osawa
typester (is_404_handler support)
2010-03-08 perl v5.28.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.