diff --git a/lib/RenderApp.pm b/lib/RenderApp.pm index d3d11e3c1..051cfd99f 100644 --- a/lib/RenderApp.pm +++ b/lib/RenderApp.pm @@ -43,6 +43,9 @@ sub startup { sanitizeHostURLs(); + # Remove default public directory from static route. + pop @{ $self->static->paths }; + print "Renderer is based at $main::basehref\n"; print "Problem attempts will be sent to $main::formURL\n"; @@ -199,12 +202,10 @@ sub sanitizeHostURLs { $ENV{baseURL} = ''; } elsif ($ENV{baseURL} =~ m!\S!) { - # ENV{baseURL} is used to build routes, so configure as "/extension" - $ENV{baseURL} = "/$ENV{baseURL}"; - warn "*** [CONFIG] baseURL should not end in a slash\n" - if $ENV{baseURL} =~ s!/$!!; - warn "*** [CONFIG] baseURL should begin with a slash\n" - unless $ENV{baseURL} =~ s!^//!/!; + # ENV{baseURL} is used to build routes, so configure as "/extension". + # Ensure ENV{baseURL} starts with a slash but doesn't end with a slash. + $ENV{baseURL} = "/$ENV{baseURL}" unless $ENV{baseURL} =~ m!^/!; + $ENV{baseURL} =~ s!/$!!; # base href must end in a slash when not hosting at the root $main::basehref = diff --git a/lib/RenderApp/Controller/Render.pm b/lib/RenderApp/Controller/Render.pm index bfae768f3..3c986eec3 100644 --- a/lib/RenderApp/Controller/Render.pm +++ b/lib/RenderApp/Controller/Render.pm @@ -10,6 +10,7 @@ use WeBWorK::PreTeXt; sub parseRequest { my $c = shift; my %params = %{ $c->req->params->to_hash }; + $params{outputFormat} ||= $params{outputformat} || 'default'; my $originIP = $c->req->headers->header('X-Forwarded-For') // '' =~ s!^\s*(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*$!$1!r; diff --git a/lib/WeBWorK/FormatRenderedProblem.pm b/lib/WeBWorK/FormatRenderedProblem.pm index bc7fcd0f0..fdc47f5e0 100644 --- a/lib/WeBWorK/FormatRenderedProblem.pm +++ b/lib/WeBWorK/FormatRenderedProblem.pm @@ -45,8 +45,8 @@ sub formatRenderedProblem { # Third party CSS my @third_party_css = map { getAssetURL($formLanguage, $_->[0]) } ( - [ 'css/bootstrap.css', ], - [ 'node_modules/jquery-ui-dist/jquery-ui.min.css', ], + ['css/bootstrap.css'], + ['node_modules/jquery-ui-dist/jquery-ui.min.css'], ['node_modules/@fortawesome/fontawesome-free/css/all.min.css'], ); @@ -54,9 +54,6 @@ sub formatRenderedProblem { # or via a setting of $ce->{pg}{specialPGEnvironmentVars}{extra_css_files} # which can be set in course.conf (the value should be an anonomous array). my @cssFiles; - # if (ref($ce->{pg}{specialPGEnvironmentVars}{extra_css_files}) eq 'ARRAY') { - # push(@cssFiles, { file => $_, external => 0 }) for @{ $ce->{pg}{specialPGEnvironmentVars}{extra_css_files} }; - # } if (ref($rh_result->{flags}{extra_css_files}) eq 'ARRAY') { push @cssFiles, @{ $rh_result->{flags}{extra_css_files} }; } @@ -87,7 +84,7 @@ sub formatRenderedProblem { ); # Get the requested format. (outputFormat or outputformat) - my $formatName = $inputs_ref->{outputFormat} || 'default'; + my $formatName = $inputs_ref->{outputFormat} || $inputs_ref->{outputformat} || 'default'; # Add JS files requested by problems via ADD_JS_FILE() in the PG file. my @extra_js_files; diff --git a/lib/WeBWorK/RenderProblem.pm b/lib/WeBWorK/RenderProblem.pm index 44bbd9c88..241bfb0bc 100644 --- a/lib/WeBWorK/RenderProblem.pm +++ b/lib/WeBWorK/RenderProblem.pm @@ -212,9 +212,9 @@ sub standaloneRenderer { showAttemptPreviews => 1, # display LaTeX version of submitted answer showHints => $showHints, # default is to showHint (set in PG.pm) showSolutions => $showSolutions, - showCorrectAnswers => $inputs_ref->{showCorrectAnswers} ? 2 : 0, - num_of_correct_ans => $inputs_ref->{numCorrect} || 0, - num_of_incorrect_ans => $inputs_ref->{numIncorrect} || 0, + showCorrectAnswers => $inputs_ref->{showCorrectAnswers} && $displayResults || 0, + num_of_correct_ans => $inputs_ref->{numCorrect} || 0, + num_of_incorrect_ans => $inputs_ref->{numIncorrect} || 0, displayMode => $inputs_ref->{displayMode}, useMathQuill => !defined $inputs_ref->{entryAssist} || $inputs_ref->{entryAssist} eq 'MathQuill', answerPrefix => $inputs_ref->{answerPrefix}, @@ -225,8 +225,8 @@ sub standaloneRenderer { language => $inputs_ref->{language} // 'en', language_subroutine => WeBWorK::Localize::getLoc($inputs_ref->{language} // 'en'), templateDirectory => "$ENV{RENDER_ROOT}/", - htmlURL => 'pg_files/', - tempURL => 'pg_files/tmp/', + htmlURL => '/pg_files/', + tempURL => '/pg_files/tmp/', debuggingOptions => { show_resource_info => $inputs_ref->{show_resource_info}, view_problem_debugging_info => $inputs_ref->{view_problem_debugging_info} diff --git a/lib/WeBWorK/Utils.pm b/lib/WeBWorK/Utils.pm index 3db77b82d..b9d890f91 100644 --- a/lib/WeBWorK/Utils.pm +++ b/lib/WeBWorK/Utils.pm @@ -49,7 +49,7 @@ sub getThirdPartyAssetURL { . substr($dependencies->{$_}, 1) . '/' . ($1 =~ s/(?:\.min)?\.(js|css)$/.min.$1/gr); } else { - return Mojo::URL->new("${baseURL}$file")->query(version => $dependencies->{$_} =~ s/#/@/gr)->to_string; + return Mojo::URL->new("$baseURL/$file")->query(version => $dependencies->{$_})->to_string; } } } @@ -99,10 +99,10 @@ sub getAssetURL { # If so, then either serve it from a CDN if requested, or serve it directly with the library version # appended as a URL parameter. if ($file =~ /^node_modules/) { - my $wwFile = getThirdPartyAssetURL($file, $thirdPartyWWDependencies, '', 0); + my $wwFile = getThirdPartyAssetURL($file, $thirdPartyWWDependencies, $ENV{baseURL}, 0); return $wwFile if $wwFile; - my $pgFile = getThirdPartyAssetURL($file, $thirdPartyPGDependencies, 'pg_files/', 1); + my $pgFile = getThirdPartyAssetURL($file, $thirdPartyPGDependencies, "$ENV{baseURL}/pg_files", 0); return $pgFile if $pgFile; } @@ -114,21 +114,22 @@ sub getAssetURL { : undef; # First check to see if this is a file in the webwork htdocs location with a rtl variant. - return "$staticWWAssets->{$rtlfile}" + return "$ENV{baseURL}/$staticWWAssets->{$rtlfile}" if defined $rtlfile && defined $staticWWAssets->{$rtlfile}; # Next check to see if this is a file in the webwork htdocs location. - return "$staticWWAssets->{$file}" if defined $staticWWAssets->{$file}; + return "$ENV{baseURL}/$staticWWAssets->{$file}" if defined $staticWWAssets->{$file}; # Now check to see if this is a file in the pg htdocs location with a rtl variant. - return "pg_files/$staticPGAssets->{$rtlfile}" if defined $rtlfile && defined $staticPGAssets->{$rtlfile}; + return "$ENV{baseURL}/pg_files/$staticPGAssets->{$rtlfile}" + if defined $rtlfile && defined $staticPGAssets->{$rtlfile}; # Next check to see if this is a file in the pg htdocs location. - return "pg_files/$staticPGAssets->{$file}" if defined $staticPGAssets->{$file}; + return "$ENV{baseURL}/pg_files/$staticPGAssets->{$file}" if defined $staticPGAssets->{$file}; # If the file was not found in the lists, then just use the given file and assume its path is relative to the # render app public folder. - return "$file"; + return "$ENV{baseURL}/$file"; } 1; diff --git a/templates/RPCRenderFormats/default.html.ep b/templates/RPCRenderFormats/default.html.ep index 81e24bf57..4beee37fb 100644 --- a/templates/RPCRenderFormats/default.html.ep +++ b/templates/RPCRenderFormats/default.html.ep @@ -4,7 +4,6 @@ >
-