Prerendering logic supplies PathBase (formatted as baseUrl) to boot logic

This commit is contained in:
SteveSandersonMS
2016-12-01 17:24:24 +00:00
parent 2b2465ad2e
commit 0a116ba2a1
4 changed files with 10 additions and 4 deletions

View File

@@ -119,7 +119,8 @@ namespace Microsoft.AspNetCore.SpaServices.Prerendering
unencodedAbsoluteUrl,
unencodedPathAndQuery,
CustomDataParameter,
TimeoutMillisecondsParameter);
TimeoutMillisecondsParameter,
request.PathBase.ToString());
if (!string.IsNullOrEmpty(result.RedirectUrl))
{

View File

@@ -30,6 +30,7 @@ namespace Microsoft.AspNetCore.SpaServices.Prerendering
/// <param name="requestPathAndQuery">The path and query part of the URL of the currently-executing HTTP request. This is supplied to the prerendering code.</param>
/// <param name="customDataParameter">An optional JSON-serializable parameter to be supplied to the prerendering code.</param>
/// <param name="timeoutMilliseconds">The maximum duration to wait for prerendering to complete.</param>
/// <param name="requestPathBase">The PathBase for the currently-executing HTTP request.</param>
/// <returns></returns>
public static Task<RenderToStringResult> RenderToString(
string applicationBasePath,
@@ -38,7 +39,8 @@ namespace Microsoft.AspNetCore.SpaServices.Prerendering
string requestAbsoluteUrl,
string requestPathAndQuery,
object customDataParameter,
int timeoutMilliseconds)
int timeoutMilliseconds,
string requestPathBase)
{
return nodeServices.InvokeExportAsync<RenderToStringResult>(
NodeScript.Value.FileName,
@@ -48,7 +50,8 @@ namespace Microsoft.AspNetCore.SpaServices.Prerendering
requestAbsoluteUrl,
requestPathAndQuery,
customDataParameter,
timeoutMilliseconds);
timeoutMilliseconds,
requestPathBase);
}
}
}

View File

@@ -7,7 +7,7 @@ import { run as domainTaskRun, baseUrl as domainTaskBaseUrl } from 'domain-task/
const defaultTimeoutMilliseconds = 30 * 1000;
export function createServerRenderer(bootFunc: BootFunc): RenderToStringFunc {
const resultFunc = (callback: RenderToStringCallback, applicationBasePath: string, bootModule: BootModuleInfo, absoluteRequestUrl: string, requestPathAndQuery: string, customDataParameter: any, overrideTimeoutMilliseconds: number) => {
const resultFunc = (callback: RenderToStringCallback, applicationBasePath: string, bootModule: BootModuleInfo, absoluteRequestUrl: string, requestPathAndQuery: string, customDataParameter: any, overrideTimeoutMilliseconds: number, requestPathBase: string) => {
// Prepare a promise that will represent the completion of all domain tasks in this execution context.
// The boot code will wait for this before performing its final render.
let domainTaskCompletionPromiseResolve;
@@ -19,6 +19,7 @@ export function createServerRenderer(bootFunc: BootFunc): RenderToStringFunc {
location: url.parse(requestPathAndQuery),
origin: parsedAbsoluteRequestUrl.protocol + '//' + parsedAbsoluteRequestUrl.host,
url: requestPathAndQuery,
baseUrl: (requestPathBase || '') + '/',
absoluteUrl: absoluteRequestUrl,
domainTasks: domainTaskCompletionPromise,
data: customDataParameter

View File

@@ -23,6 +23,7 @@ interface BootFuncParams {
location: any; // e.g., Location object containing information '/some/path'
origin: string; // e.g., 'https://example.com:1234'
url: string; // e.g., '/some/path'
baseUrl: string; // e.g., '' or '/myVirtualDir'
absoluteUrl: string; // e.g., 'https://example.com:1234/some/path'
domainTasks: Promise<any>;
data: any; // any custom object passed through from .NET