Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Dancer2 getting a wrong request uri

by PeterKaagman (Beadle)
on Sep 27, 2024 at 08:32 UTC ( [id://11161965]=perlquestion: print w/replies, xml ) Need Help??

PeterKaagman has asked for the wisdom of the Perl Monks concerning the following question:

Hi there

I know... I know... this is problably more an Apache question than Perl. But since it does involve Dancer2 I hope one of you has some experience with this. So this is my problem:

I've been doing a lot of work on Azure. using LWP to do the Graph requests. Usually just cli/backend scripting, which works just fine. But Dancer2 gets me into trouble. Azure, like other oAuth API's, needs a callback URI to accept an authentication attempt. This works just fine during development: doing port forwarding to the development host. In this case Azure gets a callback URI like http://localhost/azuread/callback

The problems start when going to production. Azure no longer receives a callback URI which can work, it should get something like https://somesite/azuread/callback, but "somesite" is replaced by the servers IP. I found the callback uri is composed of some variables, one of them being "base". This variable is by default initialized using the request URI, or can be set in the config. So I would be able to set a correct base by putting it in the config, but I'd rather have the default method of using the request URI which comes from Apache (in my case)

I'm using an Apache2 vhost with a fcgid setup, some rewrite rules "forward" the request to the dispatch.fcgi. I found a deployment guide for Dancer2 apps and am using a modified version of the fastcgi setup. I could not find an easy way to get mod_fastcgi on my host, but could get mod_fcgid from the Ubuntu repro, I adapted the vhost for mod_fcgid. And I guess something goes wrong there. This is the vhost.conf:

<VirtualHost *:80>
    ServerName somesite.somehost.nl
    DocumentRoot /var/www/somesite/public
    Redirect permanent / https://somesite.somehost.nl
</VirtualHost>
<VirtualHost *:443>
    ServerName somesite.somehost.nl
    DocumentRoot /var/www/somesite/public

    <Directory /var/www/somesite/public>
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        #AddHandler fastcgi-script .fcgi
        AddHandler fcgid-script .fcgi
        Require all granted
    </Directory>
    ErrorLog  /var/log/apache2/somesite/error_log
    CustomLog /var/log/apache2/somesite/access_log common

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ /dispatch.fcgi$1 QSA,L

    Include cert/wildcard.conf
</VirtualHost>

I suspect the Rewrite setting to be at fault. I did find settings for mod_proxy to infuence the request uri, but I'm not using mod_proxy as far as I know

Any thoughts?

Peter

Replies are listed 'Best First'.
Re: Dancer2 getting a wrong request uri
by hippo (Archbishop) on Sep 27, 2024 at 08:57 UTC

    Set up a second handler (eg. 'dispatch-test.fcgi') which just simply echoes $ENV{REQUEST_URI} to the output. That will show you whether the problem is in your Apache/mod_fcgid set-up or something else internal to dispatch.fcgi. If it turns out to be the latter then you'll need to start digging into the code.


    🦛

Re: Dancer2 getting a wrong request uri
by Anonymous Monk on Sep 29, 2024 at 00:30 UTC
    Have you tried using the 'use URI' module to manipulate the callback URI?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11161965]
Approved by marto
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-10-08 05:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (44 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.