-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
85 lines (70 loc) · 2.26 KB
/
Program.cs
File metadata and controls
85 lines (70 loc) · 2.26 KB
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
using WebApi.Endpoints;
using WebApi.Models;
using WebApi.Services;
var builder = WebApplication.CreateBuilder(args);
// Configure port (5001 for macOS, since 5000 is used by system)
builder.WebHost.ConfigureKestrel(serverOptions =>
{
serverOptions.ListenAnyIP(5001);
});
// Add services
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
// Register Weaviate client and context
// Read hostname from environment variable (default to localhost for local dev)
var weaviateHostname = builder.Configuration.GetValue<string>("Weaviate:Hostname") ?? "localhost";
var weaviateRestPort = (ushort)builder.Configuration.GetValue<int>("Weaviate:RestPort", 8080);
var weaviateGrpcPort = (ushort)builder.Configuration.GetValue<int>("Weaviate:GrpcPort", 50051);
builder.Services.AddWeaviateLocal(
hostname: weaviateHostname,
restPort: weaviateRestPort,
grpcPort: weaviateGrpcPort
);
builder.Services.AddWeaviateContext<ProductCatalogContext>(
configureOptions: null,
eagerMigration: true
);
// Register data seeder
builder.Services.AddHostedService<DataSeeder>();
// CORS for SvelteKit dev server
builder.Services.AddCors(options =>
{
options.AddDefaultPolicy(policy =>
{
policy.WithOrigins("http://localhost:5173").AllowAnyHeader().AllowAnyMethod();
});
});
var app = builder.Build();
// Ensure schema is ready before accepting requests
using (var scope = app.Services.CreateScope())
{
var context = scope.ServiceProvider.GetRequiredService<ProductCatalogContext>();
try
{
app.Logger.LogInformation("Verifying collections...");
// Migrations run automatically with eagerMigration: true
// This just ensures context is initialized before DataSeeder runs
await context.Client.IsReady();
app.Logger.LogInformation("Collections ready!");
}
catch (Exception ex)
{
app.Logger.LogError(ex, "Failed to verify collections");
throw;
}
}
// Development middleware
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseCors();
// Serve static files (product images)
app.UseStaticFiles();
// Map endpoints
app.MapHealthCheck();
app.MapProductEndpoints();
app.MapReviewEndpoints();
app.MapSearchEndpoints();
await app.RunAsync();