-
-
Save dhoss/224452 to your computer and use it in GitHub Desktop.
fix'd
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
#!/usr/bin/perl -w | |
use strict; | |
use lib $ENV{MT_HOME} ? "$ENV{MT_HOME}/lib" : 'lib'; | |
use MT::Bootstrap (); | |
use MT::App::CMS; | |
use CGI::PSGI; | |
use Plack::Middleware qw(Static); | |
use Plack::Builder; | |
my $app = sub { | |
my $cgi = CGI::PSGI->new(shift); | |
my $app = MT::App::CMS->new( CGIObject => $cgi ); | |
MT->set_instance($app); | |
# Cheap hack to get the output | |
my($header_sent, $body); | |
local *MT::App::send_http_header = sub { $header_sent++ }; | |
local *MT::App::print = sub { my $self = shift; $body .= "@_" if $header_sent }; | |
$app->init_request(CGIObject => $cgi); | |
$app->{cookies} = do { $cgi->cookie; $cgi->{'.cookies'} }; # wtf | |
$app->run; | |
# copied from MT::App::send_http_header | |
my $type = $app->{response_content_type} || 'text/html'; | |
if ( my $charset = $app->charset ) { | |
$type .= "; charset=$charset" | |
if ( $type =~ m!^text/! || $type =~ m!\+xml$! ) | |
&& $type !~ /\bcharset\b/; | |
} | |
if ($app->{redirect}) { | |
$app->{cgi_headers}{-status} = 302; | |
$app->{cgi_headers}{-location} = $app->{redirect}; | |
} else { | |
$app->{cgi_headers}{-status} | |
= ( $app->response_code || 200 ) | |
. ( $app->{response_message} ? ' ' . $app->{response_message} : '' ); | |
} | |
$app->{cgi_headers}{-type} = $type; | |
my($status, $headers) = $app->{query}->psgi_header( %{ $app->{cgi_headers} } ); | |
return [ $status, $headers, [ $body ] ]; | |
}; | |
builder { | |
enable Plack::Middleware::Static | |
path => sub { s!^/mt-static/!! }, root => "mt-static"; | |
$app; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment