Plack-Middleware-ProofOfWork

 view release on metacpan or  search on metacpan

example.psgi  view on Meta::CPAN

    ];
};

# Build middleware stack
builder {
    # Enable access log (optional)
    enable "AccessLog", format => "combined";
    
    # Proof-of-Work middleware
    enable "ProofOfWork",
        difficulty => 4,           # 4 leading zeros (approx. 1-2 seconds)
        cookie_name => 'pow',      # Cookie name
        cookie_duration => 5,      # 5 days validity
        allow_bots => 1;           # Allow search engines
        # js_file => '/path/to/custom.js';        # Optional: custom JavaScript
        # html_file => '/path/to/custom.html';    # Optional: custom HTML template
    
    $app;
};

__END__

=head1 NAME

example.psgi - Example application for Plack::Middleware::ProofOfWork

=head1 SYNOPSIS

    plackup example.psgi

=head1 DESCRIPTION

This example application demonstrates Plack::Middleware::ProofOfWork.

The application loads its HTML content from an external file 
(example-protected.html) for better separation of concerns.

=head2 Files

=over 4

=item example.psgi

This PSGI application file

=item example-protected.html

Protected content page (must be in current directory)

=back

=head1 USAGE

    # Start server
    plackup example.psgi
    
    # With specific port
    plackup -p 8080 example.psgi
    
    # Production with Starman
    starman example.psgi

=head1 TESTING

=head2 Browser Test

Visit http://localhost:5000/ in your browser.

You should see:
1. Challenge page with spinner
2. Proof-of-Work calculation
3. Automatic page reload
4. Protected content

=head2 curl Tests

    # Without JavaScript (gets challenge)
    curl http://localhost:5000/
    
    # As bot (bypasses PoW)
    curl -A "Googlebot" http://localhost:5000/
    
    # With valid cookie (bypasses PoW)
    curl -H "Cookie: pow=VALID_COOKIE" http://localhost:5000/
    
    # With invalid cookie (gets challenge)
    curl -H "Cookie: pow=invalid" http://localhost:5000/

=head1 CUSTOMIZATION

Edit the middleware configuration:

    enable "ProofOfWork",
        difficulty => 4.5,         # Harder challenge
        cookie_name => 'bot_check',
        cookie_duration => 7,      # 7 days
        allow_bots => 0;           # Block all bots

Edit example-protected.html to customize the protected page.

=head1 SEE ALSO

L<Plack::Middleware::ProofOfWork>

=cut



( run in 0.788 second using v1.01-cache-2.11-cpan-e93a5daba3e )