2
0
mirror of https://github.com/9ParsonsB/Pulsar.git synced 2025-04-05 01:29:38 -04:00
pulsar/Pulsar/Program.cs
Ben Parsons ac30d3cd2a API & WebSocket now working
Can Read Status File & Broadcast contents via websocket
2024-04-18 14:45:16 +10:00

34 lines
1.2 KiB
C#

using Lamar.Microsoft.DependencyInjection;
using Microsoft.AspNetCore.Cors.Infrastructure;
using Pulsar.Features;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddLamar();
builder.Services.AddControllersWithViews();
builder.Services.AddCors(options =>
{
options.AddDefaultPolicy(new CorsPolicy()
{ Origins = { "http://localhost:5000" }, Headers = { "*" }, Methods = { "*" } });
});
builder.Services.AddSignalR().AddJsonProtocol(options =>
options.PayloadSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull);
builder.Services.AddDbContext<PulsarContext>();
builder.Services.Configure<PulsarConfiguration>(builder.Configuration.GetSection(nameof(Pulsar)));
builder.Services.Configure<JsonOptions>(options =>
options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull);
builder.Services.AddReverseProxy().LoadFromConfig(builder.Configuration.GetSection("ReverseProxy"));
builder.Services.AddSpaYarp();
var app = builder.Build();
app.UseRouting();
app.MapReverseProxy();
app.MapControllers();
app.MapDefaultControllerRoute();
app.UseWebSockets();
app.MapHub<EventsHub>("api/events");
app.UseSpaYarp();
app.MapFallbackToFile("index.html");
await app.RunAsync();