Skip to content

Commit

Permalink
properly handle missing files
Browse files Browse the repository at this point in the history
  • Loading branch information
oetiker committed Aug 22, 2015
1 parent 83c66b2 commit 17b9e39
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
7 changes: 7 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
Revision history for Mojolicious::Pugin::Qooxdoo

0.904 2015-08-22
- don't timeout when trying to open non existing file

0.903 2015-07-16
- fix debug output regression from 0.902

0.902 2015-03-19
- only log the first 60 characters of each request unless the
environment variable MOJO_QX_FULL_RPC_DETAILS is set.
Expand Down
21 changes: 13 additions & 8 deletions lib/Mojolicious/Plugin/Qooxdoo.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use Mojo::Base 'Mojolicious::Plugin';
use File::Spec::Functions qw(splitdir updir catdir file_name_is_absolute);
use Cwd qw(abs_path);

our $VERSION = '0.903';
our $VERSION = '0.904';

sub register {
my ($self, $app, $conf) = @_;
Expand Down Expand Up @@ -70,13 +70,18 @@ sub register {
}
else {
# redirect root to index.html
$r->get($root.'(*file)' => {file => 'index.html' } => sub {
my $self = shift;
my $file = $self->param('file');
$self->req->url->path('/'.$file);
return $app->static->dispatch($self);
});
}
$r->any('/' => sub { shift->reply->static('index.html')});
if ($root ne '/'){
$app->hook(before_dispatch => sub {
my $self = shift;
my $file = $self->req->url->path->to_string;
if ($file =~ s{^$root/*}{} and -r $app->home->rel_file('public/'.$file)){
$self->req->url->path('/'.$file);
return $app->static->dispatch($self);
}
});
}
}
}

1;
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Plugin/Qooxdoo/JsonRpcController.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use Encode;

has toUTF8 => sub { find_encoding('utf8') };

our $VERSION = '0.903';
our $VERSION = '0.904';

has 'service';

Expand Down
6 changes: 5 additions & 1 deletion t/simple.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use lib $FindBin::Bin.'/../thirdparty/lib/perl5';
use lib $FindBin::Bin.'/../lib';
use lib $FindBin::Bin.'/../example/lib';

use Test::More tests => 42;
use Test::More;
use Test::Mojo;


Expand All @@ -15,6 +15,9 @@ my $t = Test::Mojo->new('QxExample');

$t->get_ok('/asdfasdf')->status_is(404);

$t->get_ok('/root/unknown.txt')
->status_is(404);

$t->get_ok('/root/demo.txt')
->content_like(qr/DemoText/)
->status_is(200);
Expand Down Expand Up @@ -67,5 +70,6 @@ $t->get_ok('/root/jsonrpc?_ScriptTransport_id=1&_ScriptTransport_data={"id":1,"s
->content_type_is('application/javascript; charset=utf-8')
->status_is(200);

done_testing();

exit 0;

0 comments on commit 17b9e39

Please sign in to comment.