-
Notifications
You must be signed in to change notification settings - Fork 765
/
UIResourceMapper.cs
47 lines (42 loc) · 1.51 KB
/
UIResourceMapper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using HealthChecks.UI.Configuration;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using System;
using System.Threading.Tasks;
namespace HealthChecks.UI.Core
{
internal class UIResourcesMapper
{
private readonly IUIResourcesReader _reader;
public UIResourcesMapper(IUIResourcesReader reader)
{
_reader = reader ?? throw new ArgumentNullException(nameof(reader));
}
public void Map(IApplicationBuilder app, Options options)
{
var resources = _reader.UIResources;
var UIMain = resources.GetMainUI(options);
foreach (var resource in resources)
{
app.Map($"{Keys.HEALTHCHECKSUI_RESOURCES_PATH}/{resource.FileName}", appBuilder =>
{
appBuilder.Run(async context =>
{
context.Response.ContentType = resource.ContentType;
await context.Response.WriteAsync(resource.Content);
});
});
}
app.Map($"{options.UIPath}", appBuilder =>
{
appBuilder.Run(context =>
{
context.Response.Headers.Add("Cache-Control", "no-cache, no-store");
context.Response.ContentType = UIMain.ContentType;
context.Response.WriteAsync(UIMain.Content);
return Task.CompletedTask;
});
});
}
}
}