public async Task <ActionResult> Index() { if (_spaSsr == null) { bool isHttps = HttpContext.Request.Headers["X-Forwarded-Proto"] == "https" || HttpContext.Request.IsHttps; string protocol = isHttps ? "https" : "http"; string host = HttpContext.Request.Host.ToString(); if (HttpContext.Request.Headers.ContainsKey("X-ORIGINAL-HOST")) { host = HttpContext.Request.Headers["X-ORIGINAL-HOST"]; } var siteUrl = $"{protocol}://{host}"; _spaSsr = new SpaSsr(_logger, _env, _httpClientFactory, _options, _cache, siteUrl, _configuration, HttpContext); } var cacheKey = HttpContext.Request.Path.ToString().ToLowerInvariant(); var relativeUrl = $"{HttpContext.Request.Path}{HttpContext.Request.QueryString}"; var renderResult = await _spaSsr.RenderSpaServerSide(cacheKey, relativeUrl, TimeSpan.FromDays(1.0)); var content = new ContentResult { Content = renderResult.Html, ContentType = "text/html" }; if (renderResult.StatusCode.HasValue) { content.StatusCode = (int)renderResult.StatusCode.Value; } return(content); }
public async Task <ActionResult> Index() { if (_spaSsr == null) { var siteUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}"; _spaSsr = new SpaSsr(_logger, _env, _httpClientFactory, _options, _cache, siteUrl); } var cacheKey = HttpContext.Request.Path.ToString().ToLowerInvariant(); var relativeUrl = $"{HttpContext.Request.Path}{HttpContext.Request.QueryString}"; var renderResult = await _spaSsr.RenderSpaServerSide(cacheKey, relativeUrl, TimeSpan.FromDays(1.0)); var content = new ContentResult { Content = renderResult.Html, ContentType = "text/html" }; return(content); }