public Task <VueRenderResult> Render(
     string moduleName,
     string exportName          = null,
     object customDataParameter = null,
     int timeoutMilliseconds    = default(int))
 {
     return(VueRenderer.Render(
                _applicationBasePath,
                _nodeServices,
                _hostingEnvironment,
                _applicationStoppingToken,
                new JavaScriptModuleExport(moduleName)
     {
         ExportName = exportName
     },
                _httpContextAccessor.HttpContext,
                customDataParameter,
                timeoutMilliseconds));
 }
Пример #2
0
        /// <summary>
        /// Executes the tag helper to perform server-side prerendering.
        /// </summary>
        /// <param name="context">The <see cref="TagHelperContext"/>.</param>
        /// <param name="output">The <see cref="TagHelperOutput"/>.</param>
        /// <returns>A <see cref="Task"/> representing the operation.</returns>
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var result = await VueRenderer.Render(
                _applicationBasePath,
                _nodeServices,
                _hostEnv,
                _applicationStoppingToken,
                new JavaScriptModuleExport(ModuleName)
            {
                ExportName = ExportName
            },
                ViewContext.HttpContext,
                CustomDataParameter,
                TimeoutMillisecondsParameter);

            if (!string.IsNullOrEmpty(result.RedirectUrl))
            {
                // It's a redirection
                ViewContext.HttpContext.Response.Redirect(result.RedirectUrl);
                return;
            }

            if (result.StatusCode.HasValue)
            {
                ViewContext.HttpContext.Response.StatusCode = result.StatusCode.Value;
            }

            // It's some HTML to inject
            output.Content.SetHtmlContent(result.Html);

            // Also attach any specified globals to the 'window' object. This is useful for transferring
            // general state between server and client.
            var globalsScript = result.CreateGlobalsAssignmentScript();

            if (!string.IsNullOrEmpty(globalsScript))
            {
                output.PostElement.SetHtmlContent($"<script>{globalsScript}</script>");
            }
        }