Reading Apache2 config from within application on top of Plack

9 views
Skip to first unread message

Manuel Jeckelmann

unread,
Jan 17, 2014, 4:49:00 AM1/17/14
to psgi-...@googlegroups.com
Hi, 

I'm trying to read environment variables from the Apache-configuration (httpd.conf) that were set either by the "PerlSetVar"- or the "PerlSetEnv"-directive within a Location-tag. The use case is to tell the application, whether it's running in a Dev, Test or Prod environment (having for example other locations to connect against a DB).

However, Plack seems to modify %ENV and thus remove the environment variable I have set by specifying PerlSetEnv within the config. On the other hand I found out, it's difficult to retrieve the global Apache2::RequestRec-object (which would contain the value set using PerlSetVar) somewhere in the middle of the application running on top of Plack. I managed to do it once by running the following code, but this does not seem to work on all servers - I did not search too much, why it worked out once but not somewhere else.

So, do you have any suggestions on how I could solve that problem (possibly without writing a new handler myself)? Or do you have even other approaches on how I could tell my application in what environment it runs (from the Apache-config)? 

Thank you!
Manuel

Manuel Jeckelmann

unread,
Jan 17, 2014, 6:00:46 AM1/17/14
to psgi-...@googlegroups.com
Ok, I should at least attach code, if I refer to it. So, *the following code* refers to:
----
$cgi = CGI->new();
$rr = $cgi->{'.r'};  # $rr would be an Apache2::RequestRec-object
$self->{isDevServer} = $rr->dir_config('dev_server');
----

Thx
Reply all
Reply to author
Forward
0 new messages