Added URLMap support (e.g. virtual hosts and mounting)

This commit is contained in:
Patrick Donelan 2010-03-18 21:38:20 -04:00
parent e15c32e3f7
commit 2516ff12c1
10 changed files with 54 additions and 22 deletions

20
eg/urlmap.psgi Normal file
View file

@ -0,0 +1,20 @@
use lib '/data/WebGUI/lib';
use WebGUI;
my $wg1 = WebGUI->new;
my $wg2 = WebGUI->new;
use Plack::Builder;
my $app = builder {
mount "http://dev.localhost.localdomain:5000/" => $wg1;
mount "/wg1" => $wg1;
mount "/wg2" => $wg2;
mount "/" => sub { [ 200, [ 'Content-Type' => 'text/html' ], [ <<END_HTML ] ] };
<p>WebGUI + URLMap</p>
<ul>
<li><a href="http://dev.localhost.localdomain:5000">Virtual Host (wG instance #1)</a></li>
<li><a href=/wg1>Nested (wG instance #1)</a></li>
<li><a href=/wg2>Nested (wG instance #2)</a></li>
</ul>
END_HTML
};

View file

@ -742,8 +742,8 @@ sub fixUrl {
# fix urls used by uploads and extras # fix urls used by uploads and extras
# and those beginning with http # and those beginning with http
my @badUrls = ( my @badUrls = (
$self->session->config->get("extrasURL"), $self->session->url->make_urlmap_work($self->session->config->get("extrasURL")),
$self->session->config->get("uploadsURL"), $self->session->url->make_urlmap_work($self->session->config->get("uploadsURL")),
); );
foreach my $badUrl (@badUrls) { foreach my $badUrl (@badUrls) {
$badUrl =~ s{ / $ }{}x; # Remove trailing slashes from the end of the URL $badUrl =~ s{ / $ }{}x; # Remove trailing slashes from the end of the URL
@ -1970,7 +1970,7 @@ sub outputWidgetMarkup {
my $assetId = $self->getId; my $assetId = $self->getId;
my $hexId = $session->id->toHex($assetId); my $hexId = $session->id->toHex($assetId);
my $conf = $session->config; my $conf = $session->config;
my $extras = $conf->get('extrasURL'); my $extras = $session->url->make_urlmap_work($conf->get('extrasURL'));
# the widgetized version of content that has the widget macro in it is # the widgetized version of content that has the widget macro in it is
# executing in an iframe. this iframe doesn't have a style object. # executing in an iframe. this iframe doesn't have a style object.
@ -2072,7 +2072,7 @@ sub prepareWidgetView {
my $self = shift; my $self = shift;
my $templateId = shift; my $templateId = shift;
my $template = WebGUI::Asset::Template->newById($self->session, $templateId); my $template = WebGUI::Asset::Template->newById($self->session, $templateId);
my $extras = $self->session->config->get('extrasURL'); my $extras = $self->session->url->make_urlmap_work($self->session->config->get('extrasURL'));
$template->prepare; $template->prepare;

View file

@ -741,7 +741,7 @@ sub view {
my $config = $session->config; my $config = $session->config;
my $eh = $session->errorHandler; my $eh = $session->errorHandler;
$var->{'extras'} = $config->get("extrasURL")."/wobject/ProjectManager"; $var->{'extras'} = $session->url->make_urlmap_work($config->get("extrasURL"))."/wobject/ProjectManager";
$var->{'project.create'} = $self->getUrl("func=editProject;projectId=new"); $var->{'project.create'} = $self->getUrl("func=editProject;projectId=new");
$var->{'project.create.label'} = $i18n->get("project new label"); $var->{'project.create.label'} = $i18n->get("project new label");
@ -904,7 +904,7 @@ sub www_drawGanttChart {
my ($dunits,$hoursPerDay) = $db->quickArray("select durationUnits,hoursPerDay from PM_project where projectId=".$db->quote($projectId)); my ($dunits,$hoursPerDay) = $db->quickArray("select durationUnits,hoursPerDay from PM_project where projectId=".$db->quote($projectId));
$var->{'extras'} = $config->get("extrasURL")."/wobject/ProjectManager"; $var->{'extras'} = $session->url->make_urlmap_work($config->get("extrasURL"))."/wobject/ProjectManager";
#Initialize display settings #Initialize display settings
my $projectDisplay = "weeks"; my $projectDisplay = "weeks";
@ -1494,8 +1494,8 @@ sub www_editTask {
}); });
$var->{'form.footer'} = WebGUI::Form::formFooter($session); $var->{'form.footer'} = WebGUI::Form::formFooter($session);
$var->{'extras'} = $config->get("extrasURL"); $var->{'extras'} = $session->url->make_urlmap_work($config->get("extrasURL"));
$var->{'assetExtras'} = $config->get("extrasURL").'/wobject/ProjectManager'; $var->{'assetExtras'} = $session->url->make_urlmap_work($config->get("extrasURL")).'/wobject/ProjectManager';
$var->{'task_name_label'} = $i18n->get('task name label'); $var->{'task_name_label'} = $i18n->get('task name label');
$var->{'task_start_label'} = $i18n->get('task start label'); $var->{'task_start_label'} = $i18n->get('task start label');
@ -1726,8 +1726,8 @@ sub www_viewProject {
return $privilege->insufficient unless $self->_userCanObserveProject($user, $projectId); return $privilege->insufficient unless $self->_userCanObserveProject($user, $projectId);
#Set extras template variables #Set extras template variables
my $extras = $config->get("extrasURL"); my $extras = $session->url->make_urlmap_work($config->get("extrasURL"));
my $assetExtras = $config->get("extrasURL")."/wobject/ProjectManager"; my $assetExtras = $session->url->make_urlmap_work($config->get("extrasURL"))."/wobject/ProjectManager";
$var->{'extras' } = $assetExtras; $var->{'extras' } = $assetExtras;
$var->{'extras.base'} = $extras; $var->{'extras.base'} = $extras;

View file

@ -185,7 +185,7 @@ sub view {
my ($session,$privilege,$form,$db,$dt,$user,$eh,$config) = $self->getSessionVars("privilege","form","db","datetime","user","errorHandler","config"); my ($session,$privilege,$form,$db,$dt,$user,$eh,$config) = $self->getSessionVars("privilege","form","db","datetime","user","errorHandler","config");
my $i18n = WebGUI::International->new($session,'Asset_TimeTracking'); my $i18n = WebGUI::International->new($session,'Asset_TimeTracking');
$var->{'extras'} = $config->get("extrasURL")."/wobject/TimeTracking"; $var->{'extras'} = $session->url->make_urlmap_work($config->get("extrasURL"))."/wobject/TimeTracking";
if($user->isInGroup($self->groupToManage)) { if($user->isInGroup($self->groupToManage)) {
$var->{'project.manage.url'} = $self->getUrl("func=manageProjects"); $var->{'project.manage.url'} = $self->getUrl("func=manageProjects");
@ -337,7 +337,7 @@ sub www_editProject {
return $privilege->insufficient unless ($user->isInGroup($self->groupToManage)); return $privilege->insufficient unless ($user->isInGroup($self->groupToManage));
my $projectId = $_[0] || $form->get("projectId") || "new"; my $projectId = $_[0] || $form->get("projectId") || "new";
my $taskError = qq|<br><span style="color:red;font-weight:bold">$_[1]</span>| if($_[1]); my $taskError = qq|<br><span style="color:red;font-weight:bold">$_[1]</span>| if($_[1]);
my $extras = $config->get("extrasURL")."/wobject/TimeTracking"; my $extras = $session->url->make_urlmap_work($config->get("extrasURL"))."/wobject/TimeTracking";
my $project = $db->quickHashRef("select * from TT_projectList where projectId=".$db->quote($projectId)); my $project = $db->quickHashRef("select * from TT_projectList where projectId=".$db->quote($projectId));
#Build Form #Build Form
@ -509,7 +509,7 @@ sub www_manageProjects {
my $pnLabel = $i18n->get("manage project name label"); my $pnLabel = $i18n->get("manage project name label");
my $atLabel = $i18n->get("manage project available task label"); my $atLabel = $i18n->get("manage project available task label");
my $resLabel = $i18n->get("manage project resource label"); my $resLabel = $i18n->get("manage project resource label");
my $extras = $config->get("extrasURL")."/wobject/TimeTracking"; my $extras = $session->url->make_urlmap_work($config->get("extrasURL"))."/wobject/TimeTracking";
my $errorMessage = ""; my $errorMessage = "";
$errorMessage = qq|<span style="color:red;font-weight:bold">$_[0]</span>| if($_[0]); $errorMessage = qq|<span style="color:red;font-weight:bold">$_[0]</span>| if($_[0]);

View file

@ -636,9 +636,9 @@ sub exportSymlinkExtrasUploads {
my $config = $session->config; my $config = $session->config;
my $extrasPath = $config->get('extrasPath'); my $extrasPath = $config->get('extrasPath');
my $extrasUrl = $config->get('extrasURL'); my $extrasUrl = $session->url->make_urlmap_work($config->get('extrasURL'));
my $uploadsPath = $config->get('uploadsPath'); my $uploadsPath = $config->get('uploadsPath');
my $uploadsUrl = $config->get('uploadsURL'); my $uploadsUrl = $session->url->make_urlmap_work($config->get('uploadsURL'));
# we have no assurance whether the exportPath is valid or not, so check it. # we have no assurance whether the exportPath is valid or not, so check it.
my $exportPath = WebGUI::Asset->exportCheckPath($session); my $exportPath = WebGUI::Asset->exportCheckPath($session);

View file

@ -92,8 +92,8 @@ sub process {
my $uploadsDir = Path::Class::Dir->new($session->config->get('uploadsPath')); my $uploadsDir = Path::Class::Dir->new($session->config->get('uploadsPath'));
my $extrasDir = Path::Class::Dir->new($session->config->get('extrasPath')); my $extrasDir = Path::Class::Dir->new($session->config->get('extrasPath'));
my $uploadsUrl = Path::Class::Dir->new($session->config->get('uploadsURL')); my $uploadsUrl = Path::Class::Dir->new($session->url->make_urlmap_work($session->config->get('uploadsURL')));
my $extrasUrl = Path::Class::Dir->new($session->config->get('extrasURL')); my $extrasUrl = Path::Class::Dir->new($session->url->make_urlmap_work($session->config->get('extrasURL')));
##Normal mode ##Normal mode
if (! $session->var->isAdminOn) { if (! $session->var->isAdminOn) {

View file

@ -33,7 +33,7 @@ sub process {
# Get location for CSS and JS files # Get location for CSS and JS files
my $conf = $session->config; my $conf = $session->config;
my $extras = $conf->get("extrasURL"); my $extras = $session->url->make_urlmap_work($conf->get("extrasURL"));
# add CSS and JS to the page # add CSS and JS to the page
my $style = $session->style; my $style = $session->style;

View file

@ -144,7 +144,7 @@ consecutive slashes in the path part of the URL will be replaced with a single s
sub extras { sub extras {
my $self = shift; my $self = shift;
my $path = shift; my $path = shift;
my $url = $self->session->config->get("extrasURL"); my $url = $self->session->url->make_urlmap_work($self->session->config->get("extrasURL"));
my $cdnCfg = $self->session->config->get('cdn'); my $cdnCfg = $self->session->config->get('cdn');
if ( $cdnCfg and $cdnCfg->{'enabled'} and $cdnCfg->{'extrasCdn'} ) { if ( $cdnCfg and $cdnCfg->{'enabled'} and $cdnCfg->{'extrasCdn'} ) {
unless ( $path and grep $path =~ m/$_/, @{ $cdnCfg->{'extrasExclude'} } ) { unless ( $path and grep $path =~ m/$_/, @{ $cdnCfg->{'extrasExclude'} } ) {
@ -190,7 +190,7 @@ sub gateway {
my $pageUrl = shift; my $pageUrl = shift;
my $pairs = shift; my $pairs = shift;
my $skipPreventProxyCache = shift; my $skipPreventProxyCache = shift;
my $url = $self->session->config->get("gateway").'/'.$pageUrl; my $url = $self->make_urlmap_work($self->session->config->get("gateway")).'/'.$pageUrl;
$url =~ s/\/+/\//g; $url =~ s/\/+/\//g;
if ($self->session->setting->get("preventProxyCache") == 1 and !$skipPreventProxyCache) { if ($self->session->setting->get("preventProxyCache") == 1 and !$skipPreventProxyCache) {
$url = $self->append($url,"noCache=".randint(0,1000).':'.$self->session->datetime->time()); $url = $self->append($url,"noCache=".randint(0,1000).':'.$self->session->datetime->time());
@ -198,7 +198,19 @@ sub gateway {
if ($pairs) { if ($pairs) {
$url = $self->append($url,$pairs); $url = $self->append($url,$pairs);
} }
return $url;
return $url;
}
# Temporary hack
sub make_urlmap_work {
my $self = shift;
my $url = shift;
my $uri = $self->session->request->base;
$uri->path($uri->path . $url);
my $path = $uri->path;
$path =~ s{^//}{/};
return $path;
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------

View file

@ -1265,7 +1265,7 @@ If specified, we'll return a URL to the file rather than the storage location.
sub getUrl { sub getUrl {
my $self = shift; my $self = shift;
my $file = shift; my $file = shift;
my $url = $self->session->config->get("uploadsURL") . '/' . $self->getPathFrag; my $url = $self->session->url->make_urlmap_work($self->session->config->get("uploadsURL")) . '/' . $self->getPathFrag;
my $cdnCfg = $self->session->config->get('cdn'); my $cdnCfg = $self->session->config->get('cdn');
if ( $cdnCfg if ( $cdnCfg
and $cdnCfg->{'enabled'} and $cdnCfg->{'enabled'}