URL Root (or prefix)

538 views
Skip to first unread message

s...@bykov.odessa.ua

unread,
Nov 8, 2011, 1:40:46 PM11/8/11
to mojol...@googlegroups.com
Hello. I have a little question
Mojolicious works as CGI script (using apache mod rewrite in .htaccess)

$self->redirect_to('/someurl');
generates:
/cgi-bin/script/myapp/someurl

Is it possible to genarete correct redirections to '/someurl' instead of
'/cgi-bin/...'?

Anton Ukolov

unread,
Nov 17, 2011, 7:51:26 AM11/17/11
to mojol...@googlegroups.com
Hello.

hmm... I had similar problem, but with FCGI
This solved my problem:
$self->hook( before_dispatch => sub {
    my $self = shift;
    $self->req->url->base( Mojo::URL->new(q{http://your-domain.com/}) );
});

Try to put it to 'startup' method.



--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To post to this group, send email to mojol...@googlegroups.com.
To unsubscribe from this group, send email to mojolicious+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mojolicious?hl=en.


Tobias Oetiker

unread,
Nov 17, 2011, 7:58:41 AM11/17/11
to mojol...@googlegroups.com
Anton,

I use the following variant (and does not require the website to be
hardcoded).

$self->hook( before_dispatch => sub {
my $self = shift;

my $uri = $self->req->env->{SCRIPT_URI};
$self->req->url->base(Mojo::URL->new($uri)) if $uri;
});

cheers
tobi


Today Anton Ukolov wrote:

> Hello.
>
> hmm... I had similar problem, but with FCGI
> This solved my problem:
> $self->hook( before_dispatch => sub {
> my $self = shift;
> $self->req->url->base( Mojo::URL->new(q{http://your-domain.com/}) );
> });
>
> Try to put it to 'startup' method.
>
> 2011/11/8 s...@bykov.odessa.ua <s...@bykov.odessa.ua>
>
> > Hello. I have a little question
> > Mojolicious works as CGI script (using apache mod rewrite in .htaccess)
> >

> > $self->redirect_to('/someurl')**;


> > generates:
> > /cgi-bin/script/myapp/someurl
> >
> > Is it possible to genarete correct redirections to '/someurl' instead of
> > '/cgi-bin/...'?
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Mojolicious" group.
> > To post to this group, send email to mojol...@googlegroups.com.

> > To unsubscribe from this group, send email to mojolicious+unsubscribe@**
> > googlegroups.com <mojolicious%2Bunsu...@googlegroups.com>.
> > For more options, visit this group at http://groups.google.com/**
> > group/mojolicious?hl=en <http://groups.google.com/group/mojolicious?hl=en>
> > .
> >
> >
>
>

--
Tobi Oetiker, OETIKER+PARTNER AG, Aarweg 15 CH-4600 Olten, Switzerland
http://it.oetiker.ch to...@oetiker.ch ++41 62 775 9902 / sb: -9900

Anton Ukolov

unread,
Nov 17, 2011, 8:36:48 AM11/17/11
to mojol...@googlegroups.com
Yes, you are right, i gave variant that can be improved.
I prefer to move $uri to the config file.

2011/11/17 Tobias Oetiker <to...@oetiker.ch>
To unsubscribe from this group, send email to mojolicious...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mojolicious?hl=en.


sri

unread,
Nov 17, 2011, 8:51:08 AM11/17/11
to Mojolicious
Hmm, i don't quite get why so many of you hack the request URL, do we
have to review our CGI environment tests?

https://github.com/kraih/mojo/blob/master/t/mojo/request_cgi.t

--
sebastian

Tobias Oetiker

unread,
Nov 17, 2011, 9:03:40 AM11/17/11
to Mojolicious
Hi Sri,

Today sri wrote:

We sad CGI/FCGI people like to hide the name of our script from the
user. Makeing the appropriate URLs work is quite simple using
mod_rewrite in apache.

RewriteEngine On
RewriteBase /~oetiker/extopus
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) ep.fcgi/$1 [L]

But since you are using SCRIPT_NAME in Mojo/Message/Request.pm
to figure out the base url, you are calling our bluff, and if Mojo
is asked to create an url the name of the script pops back up.

mod_rewrite provieds a SCRIPT_URI environment contains a
"sanitized" version of that information, so that the name of the
script remains hidden.

obviously SCRIPT_URI may not exist, so one has to tread carefully
here ...

cheers
tobi

> --
> sebastian

Sebastian Riedel

unread,
Nov 17, 2011, 9:44:44 AM11/17/11
to mojol...@googlegroups.com
mod_rewrite provieds a SCRIPT_URI environment contains a
"sanitized" version of that information, so that the name of the
script remains hidden.

obviously SCRIPT_URI may not exist, so one has to tread carefully
here ...

I wonder if these mod_rewrite tests are incorrect, they were provided by a third party and i just made them pass.


Tobias Oetiker

unread,
Nov 17, 2011, 10:07:33 AM11/17/11
to mojol...@googlegroups.com
Hi Sebastian,

Today Sebastian Riedel wrote:

> > mod_rewrite provieds a SCRIPT_URI environment contains a
> > "sanitized" version of that information, so that the name of
> > the
> > script remains hidden.
> >
> > obviously SCRIPT_URI may not exist, so one has to tread
> > carefully
> > here ...
> >
> >
>
>
> I wonder if these mod_rewrite tests are incorrect, they were
> provided by a third party and i just made them pass.
>
> https://github.com/kraih/mojo/blob/master/t/mojo/request_cgi.t#L439

he is not looking at SCRIPT_URI which is realy central in this
matter as far as I see it, since it points to the 'script' and does
not include PATH_INFO ... whereas REQUEST_URI includes PATH_INFO
... (one could be built from the other, though).

if Mojo made any use of SCRIPT_URI that is ...

cheers
tobi

Sebastian Riedel

unread,
Nov 17, 2011, 10:17:39 AM11/17/11
to mojol...@googlegroups.com
he is not looking at SCRIPT_URI which is realy central in this
matter as far as I see it, since it points to the 'script' and does
not include PATH_INFO ... whereas REQUEST_URI includes PATH_INFO
... (one could be built from the other, though).

if Mojo made any use of SCRIPT_URI that is ...

The question is if the current behavior is right or wrong.
I would accept patches if it was proven to be wrong.

Tobias Oetiker

unread,
Nov 17, 2011, 10:25:29 AM11/17/11
to mojol...@googlegroups.com
Hi Sebastian,

Today Sebastian Riedel wrote:

> > he is not looking at SCRIPT_URI which is realy central in this
> > matter as far as I see it, since it points to the 'script' and does
> > not include PATH_INFO ... whereas REQUEST_URI includes PATH_INFO
> > ... (one could be built from the other, though).
> >
> > if Mojo made any use of SCRIPT_URI that is ...
>
> The question is if the current behavior is right or wrong.
> I would accept patches if it was proven to be wrong.

In the absence of SCRIPT_URI I would say the behaviour is correct.
If SCRIPT_URI is present, then there is room for improvement, as
Mojo is actually exposing internal information of the web server
(the name of the script) where this could be prevented.

but a proof ... difficult :-)

Sebastian Riedel

unread,
Nov 17, 2011, 11:00:02 AM11/17/11
to mojol...@googlegroups.com
In the absence of SCRIPT_URI I would say the behaviour is correct.
If SCRIPT_URI is present, then there is room for improvement, as
Mojo is actually exposing internal information of the web server
(the name of the script) where this could be prevented.

but a proof ... difficult :-)

Ok, then they are at least incomplete, i'll remove them for now.

John Stoffel

unread,
Apr 26, 2012, 3:14:27 PM4/26/12
to mojol...@googlegroups.com

Hi all,

I've read the page on howto test Mojolicious::Lite apps, but I'm
obviously missing something when I read:

https://github.com/kraih/mojo/wiki/Testing

and the example of testing a Mojolicious::Lite app. It's not clear if
this is a completely seperate script which needs to be run, or if it's
a fragment to be put into @@ t/test.pl in the __DATA__ section.

I even found the following blog entry, which looks good, but doesn't
answer the question either.

http://blogs.perl.org/users/tempire/2012/02/mojolicious-full-and-lite-apps---understanding-the-difference.html

It boils down to 1) do I include the tests into my Mojolicious::Lite
app foo.pl file or do I need to keep the tests seperate?

Thanks,
John

John Stoffel

unread,
Apr 26, 2012, 3:23:36 PM4/26/12
to mojol...@googlegroups.com

Just to be nicer about it, this is what I'm trying to do:

#!/usr/bin/perl -w

use Mojolicious::Lite;

get '/' => sub {
my $self = shift;
$self->render(text => 'Hello world!');
};

app->start;

__DATA__;

@@ t/test.pl
use Test::More;
use Test::Mojo;

use FindBin;
$ENV{MOJO_HOME} = "$FindBin::Bin/../";
require "$ENV{MOJO_HOME}/test-tests.pl";

my $t = Test::Mojo->new;
$t->get_ok('/')
->status_is(200)
->text_like('html body' => qr/Hello world/);;
done_testing;


but it just says:

> perl test-tests.pl Test
Can't find test directory.


so I'm doing something wrong, or not understanding how to make this
work properly.

Thanks,
John

John Stoffel

unread,
Apr 26, 2012, 10:17:59 PM4/26/12
to mojol...@googlegroups.com
>>>>> "John" == John Stoffel <jo...@stoffel.org> writes:


John> __DATA__;

John> @@ t/test.pl

Duh, I'm a moron. I needs to be:

@@ t/test.t

duh duh duh... At least now it runs a test, even though I'm still
failing. Baby steps... baby steps. :]

John

John Stoffel

unread,
Apr 27, 2012, 9:32:27 AM4/27/12
to mojol...@googlegroups.com
>>>>> "John" == John Stoffel <jo...@stoffel.org> writes:

>>>>> "John" == John Stoffel <jo...@stoffel.org> writes:
John> __DATA__;

John> @@ t/test.pl

John> Duh, I'm a moron. I needs to be:

John> @@ t/test.t

John> duh duh duh... At least now it runs a test, even though I'm still
John> failing. Baby steps... baby steps. :]

And I'm still a moron. I had a t/test.t file still around in the same
directory as my test ::Lite app. So it looks like while I can include
static files into Mojolicious::Lite apps, I can't include the test
stuff.

That's ok I guess, I was just trying to get a clarification on how to
do tests properly, since I should move in that direction.

It's been pretty silent here, I must be very boring to read. *grin*

John
Reply all
Reply to author
Forward
0 new messages