Created
May 29, 2012 11:16
-
-
Save rightgo09/2827889 to your computer and use it in GitHub Desktop.
steraming sample Amon2's app.psgi.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use utf8; | |
use File::Spec; | |
use File::Basename; | |
use lib File::Spec->catdir(dirname(__FILE__), 'extlib', 'lib', 'perl5'); | |
use lib File::Spec->catdir(dirname(__FILE__), 'lib'); | |
use Plack::Builder; | |
use T::Web; | |
use T; | |
use Plack::Session::Store::DBI; | |
use Plack::Session::State::Cookie; | |
use DBI; | |
{ | |
my $c = T->new(); | |
$c->setup_schema(); | |
} | |
my $db_config = T->config->{DBI} || die "Missing configuration for DBI"; | |
builder { | |
enable 'Plack::Middleware::Static', | |
#path => qr{^(?:/app/static/)}, | |
path => sub { s!^/app/static/!! }, | |
root => File::Spec->catdir(dirname(__FILE__), 'static'); | |
enable 'Plack::Middleware::Static', | |
path => qr{^(?:/robots\.txt|/favicon\.ico)$}, | |
root => File::Spec->catdir(dirname(__FILE__), 'static'); | |
enable 'Plack::Middleware::ReverseProxy'; | |
enable 'Plack::Middleware::Session', | |
store => Plack::Session::Store::DBI->new( | |
get_dbh => sub { | |
DBI->connect( @$db_config ) | |
or die $DBI::errstr; | |
} | |
), | |
state => Plack::Session::State::Cookie->new( | |
httponly => 1, | |
); | |
mount '/app' => T::Web->to_app(); | |
mount '/streaming' => sub { | |
my $env = shift; | |
return sub { | |
my $responder = shift; | |
my $writer = $responder->([ 200, []]); | |
for ( 1..5 ) { | |
$writer->write("hoge\n"); | |
sleep 1; | |
} | |
$writer->close; | |
}; | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment