Files
ASPReactDemo/Api/Program.cs
Frederic Beckmann 72b7902b55 Remove unused React logo SVG and add new API client and layouts
The React logo SVG file was removed as it was no longer needed. Introduced an auto-generated API client class (`ApiClient.ts`) for handling server communication and added new components for the navigation menu and higher-order layouts (`NavMenu`, `with_main_layout.ts.tsx`). Updated `yarn.lock` to replace legacy URL references.
2025-02-09 00:00:05 +01:00

66 lines
1.7 KiB
C#

using Api.SignalR;
using Microsoft.AspNetCore.SignalR;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddOpenApi();
builder.Services.AddSignalR();
builder.Services.AddHostedService<SignalRSendService>();
builder.Services.AddSingleton<IUserIdProvider, UserProvider>();
builder.Services.AddOpenApiDocument(config => { config.Title = "NSwag Demo API"; });
builder.Services.AddCors(options =>
{
options.AddDefaultPolicy(policy =>
{
policy.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod();
});
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
app.UseOpenApi();
app.UseSwaggerUi();
}
app.UseHttpsRedirection();
app.UseCors();
var summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
app.MapGet("/weatherforecast", async () =>
{
var forecast = Enumerable.Range(1, 2500).Select(index =>
new WeatherForecast
(
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
Random.Shared.Next(-20, 55),
summaries[Random.Shared.Next(summaries.Length)]
))
.ToArray();
return forecast;
})
.WithName("GetWeatherForecast");
// Add SignalR hub
app.MapHub<WeatherUpdateHub>("/WeatherUpdateHub");
app.Run();
record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
{
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}