StaticWebAssetDocsContentProvider.cs 1023 B

12345678910111213141516171819202122232425
  1. using Microsoft.Extensions.FileProviders;
  2. using Shared.Rcl.Docs;
  3. namespace RackPeek.Web;
  4. /// <summary>
  5. /// Reads the docs directly from the composed static web assets
  6. /// (Shared.Rcl's wwwroot in development, wwwroot/_content/Shared.Rcl in a
  7. /// published app), so the server never has to call back to its own public
  8. /// URL — which is unreachable from inside the container behind a reverse
  9. /// proxy (issue #304).
  10. /// </summary>
  11. public class StaticWebAssetDocsContentProvider(IWebHostEnvironment environment) : IDocsContentProvider {
  12. public async Task<string> GetAsync(string fileName) {
  13. IFileInfo file = environment.WebRootFileProvider
  14. .GetFileInfo($"_content/Shared.Rcl/raw_docs/{fileName}");
  15. if (!file.Exists)
  16. throw new FileNotFoundException($"Docs file '{fileName}' not found.");
  17. await using Stream stream = file.CreateReadStream();
  18. using var reader = new StreamReader(stream);
  19. return await reader.ReadToEndAsync();
  20. }
  21. }