mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-24 18:47:30 +00:00
38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.NodeServices;
|
|
|
|
namespace Microsoft.AspNetCore.SpaServices.Prerendering
|
|
{
|
|
public static class Prerenderer
|
|
{
|
|
private static readonly Lazy<StringAsTempFile> NodeScript;
|
|
|
|
static Prerenderer()
|
|
{
|
|
NodeScript = new Lazy<StringAsTempFile>(() =>
|
|
{
|
|
var script = EmbeddedResourceReader.Read(typeof(Prerenderer), "/Content/Node/prerenderer.js");
|
|
return new StringAsTempFile(script); // Will be cleaned up on process exit
|
|
});
|
|
}
|
|
|
|
public static Task<RenderToStringResult> RenderToString(
|
|
string applicationBasePath,
|
|
INodeServices nodeServices,
|
|
JavaScriptModuleExport bootModule,
|
|
string requestAbsoluteUrl,
|
|
string requestPathAndQuery,
|
|
object customDataParameter)
|
|
{
|
|
return nodeServices.InvokeExportAsync<RenderToStringResult>(
|
|
NodeScript.Value.FileName,
|
|
"renderToString",
|
|
applicationBasePath,
|
|
bootModule,
|
|
requestAbsoluteUrl,
|
|
requestPathAndQuery,
|
|
customDataParameter);
|
|
}
|
|
}
|
|
} |