Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Commit e3d1f07

Browse files
Add API for supplying custom data to prerenderer
1 parent 7e92413 commit e3d1f07

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/Microsoft.AspNetCore.SpaServices.Extensions/Prerendering/SpaPrerenderingExtensions.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ public static class SpaPrerenderingExtensions
3030
/// <param name="entryPoint">The path, relative to your application root, of the JavaScript file containing prerendering logic.</param>
3131
/// <param name="buildOnDemand">Optional. If specified, executes the supplied <see cref="ISpaPrerendererBuilder"/> before looking for the <paramref name="entryPoint"/> file. This is only intended to be used during development.</param>
3232
/// <param name="excludeUrls">Optional. If specified, requests within these URL paths will bypass the prerenderer.</param>
33+
/// <param name="supplyData">Optional. If specified, this callback will be invoked during prerendering, allowing you to pass additional data to the prerendering entrypoint code.</param>
3334
public static void UseSpaPrerendering(
3435
this IApplicationBuilder appBuilder,
3536
string entryPoint,
3637
ISpaPrerendererBuilder buildOnDemand = null,
37-
string[] excludeUrls = null)
38+
string[] excludeUrls = null,
39+
Action<HttpContext, IDictionary<string, object>> supplyData = null)
3840
{
3941
if (string.IsNullOrEmpty(entryPoint))
4042
{
@@ -107,8 +109,7 @@ public static void UseSpaPrerendering(
107109
{ "originalHtml", Encoding.UTF8.GetString(outputBuffer.GetBuffer()) }
108110
};
109111

110-
// TODO: Add an optional "supplyCustomData" callback param so people using
111-
// UsePrerendering() can, for example, pass through cookies into the .ts code
112+
supplyData?.Invoke(context, customData);
112113

113114
var (unencodedAbsoluteUrl, unencodedPathAndQuery) = GetUnencodedUrlAndPathQuery(context);
114115
var renderResult = await Prerenderer.RenderToString(

0 commit comments

Comments
 (0)