Skip to content

Commit 67200b6

Browse files
committed
Add swagger ui
1 parent 692f489 commit 67200b6

1 file changed

Lines changed: 29 additions & 8 deletions

File tree

Program.cs

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,49 @@
1+
using cubets_core.Data;
12
using cubets_core.Hubs;
2-
using cubets_core.Modules.Score.Services;
3-
using MySqlConnector;
3+
using Microsoft.AspNetCore.Builder;
4+
using Microsoft.EntityFrameworkCore;
45

56
var builder = WebApplication.CreateBuilder(args);
67

7-
builder.Services.AddMySqlDataSource(builder.Configuration.GetConnectionString("Default")!);
8+
// EF Core / MySQL
9+
builder.Services.AddDbContext<CubetsDbContext>(options =>
10+
options.UseMySql(
11+
builder.Configuration.GetConnectionString("Default"),
12+
ServerVersion.AutoDetect(builder.Configuration.GetConnectionString("Default"))
13+
));
814

15+
// SignalR
916
builder.Services.AddSignalR();
1017

18+
// Controllers
1119
builder.Services.AddControllers();
12-
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
13-
builder.Services.AddOpenApi();
20+
21+
// OpenAPI / Swagger
22+
builder.Services.AddEndpointsApiExplorer(); // wajib sebelum builder.Build()
23+
builder.Services.AddSwaggerGen();
1424

1525
var app = builder.Build();
16-
// Configure the HTTP request pipeline.
26+
27+
// Swagger UI hanya di Development
1728
if (app.Environment.IsDevelopment())
1829
{
19-
app.MapOpenApi();
30+
app.UseSwagger(); // JSON OpenAPI
31+
app.UseSwaggerUI(); // Swagger UI di /swagger
2032
}
2133

34+
// Middleware
2235
app.UseHttpsRedirection();
23-
2436
app.UseAuthorization();
2537

38+
// Redirect root "/" ke Swagger UI
39+
app.MapGet("/", context =>
40+
{
41+
context.Response.Redirect("/swagger");
42+
return Task.CompletedTask;
43+
});
44+
45+
// Endpoint Controller dan Hub
2646
app.MapControllers();
2747
app.MapHub<GameHub>("/gamehub");
48+
2849
app.Run();

0 commit comments

Comments
 (0)