-
Notifications
You must be signed in to change notification settings - Fork 3
/
Program.cs
96 lines (79 loc) · 3.08 KB
/
Program.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.Extensions.Azure;
using Azure;
using Contonance.Extensions;
using Contonance.WebPortal.Server.Clients;
using Contonance.WebPortal.Client;
using Microsoft.ApplicationInsights.AspNetCore.Extensions;
var builder = WebApplication.CreateBuilder(args);
if (builder.Environment.IsDevelopment())
{
// Workaround because blazorwasm debugger does not support envFile
var root = Directory.GetCurrentDirectory();
var dotenv = Path.Combine(root, "../../../local.env");
DotEnv.Load(dotenv);
}
builder.Configuration
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", true, true)
.AddEnvironmentVariables()
.AddAzureAppConfiguration(options =>
{
options.Connect(builder.Configuration
.GetValue<string>("AppConfiguration:ConnectionString"))
.UseFeatureFlags(options =>
{
options.CacheExpirationInterval = TimeSpan.FromSeconds(2);
});
});
builder.Services.AddLogging(config =>
{
config.AddDebug();
config.AddConsole();
});
builder.Services.AddApplicationInsightsTelemetry(options =>
{
options.DeveloperMode = true; // Only for demo purposes, do not use in production!
});
builder.Services.AddSingleton<ITelemetryInitializer>(_ => new CloudRoleNameTelemetryInitializer("Contonance.WebPortal.Server"));
builder.Services.AddAzureAppConfiguration();
builder.Services.AddAzureClients(b =>
{
b.AddEventHubProducerClient(builder.Configuration.GetValue<string>("EventHub:EventHubConnectionString"), builder.Configuration.GetValue<string>("EventHub:EventHubName"));
//Added config to enable/disable Azure OpenAI Service DI for demo purposes
if (builder.Configuration.GetValue<bool>("AzureOpenAiServiceEnabled")) {
b.AddOpenAIClient(new Uri(builder.Configuration.GetNoEmptyStringOrThrow("AzureOpenAiServiceEndpoint")), new AzureKeyCredential(builder.Configuration.GetNoEmptyStringOrThrow("AzureOpenAiKey")));
}
});
builder.Services
.AddHttpClient<ContonanceBackendClient>()
.AddPolicyConfiguration(ContonanceBackendClient.SelectPolicy, builder.Configuration);
builder.Services.AddControllersWithViews();
builder.Services.AddRazorPages();
builder.WebHost.UseStaticWebAssets();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseWebAssemblyDebugging();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseAzureAppConfiguration();
app.UseHttpsRedirection();
app.UseBlazorFrameworkFiles();
app.UseStaticFiles();
app.UseRouting();
app.MapRazorPages();
app.MapControllers();
app.MapFallbackToFile("index.html", new StaticFileOptions()
{
OnPrepareResponse = ctx =>
{
ctx.Context.Response.Cookies.Append("ai_connString", app.Configuration["ApplicationInsights:ConnectionString"]!);
}
});
app.Run();