configure grpc

This commit is contained in:
2026-01-17 18:08:16 -05:00
parent fc80e50c26
commit b762139243
27 changed files with 467 additions and 500 deletions

45
AZKiServer/Program.cs Normal file
View File

@@ -0,0 +1,45 @@
using AZKiServer.Models;
using AZKiServer.Services;
using MongoDB.Driver;
var builder = WebApplication.CreateBuilder(args);
var config = builder.Configuration;
var dbString = config["DB_STRING"];
var dbClient = new MongoClient(dbString);
var db = dbClient.GetDatabase("AZKi");
// Add services to the container.
builder.Services.AddSingleton(dbClient);
builder.Services.AddSingleton<IMongoDatabase>(db);
builder.Services.AddGrpc();
builder.Services.AddControllers(opt => opt.ModelBinderProviders.Add(new BsonIdModelBinderProvider()));
builder.Services.AddHostedService<FileScannerService>();
builder.Services.AddTransient<MediaService>();
builder.Services.AddCors(o =>
{
o.AddPolicy("AllowAll", p =>
{
p.AllowAnyOrigin();
p.AllowAnyMethod();
p.AllowAnyHeader();
});
o.AddPolicy("RPC", p =>
{
p.AllowAnyMethod();
p.AllowAnyHeader();
p.WithExposedHeaders("Grpc-Status", "Grpc-Message", "Grpc-Encoding", "Grpc-Accept-Encoding");
p.AllowAnyOrigin();
});
});
var app = builder.Build();
// Configure the HTTP request pipeline.
//app.MapGrpcService<GreeterService>();
app.MapFallbackToFile("index.html");
app.Run();