|
| 1 | +using cubets_core.Data; |
1 | 2 | using cubets_core.Hubs; |
2 | | -using cubets_core.Modules.Score.Services; |
3 | | -using MySqlConnector; |
| 3 | +using Microsoft.AspNetCore.Builder; |
| 4 | +using Microsoft.EntityFrameworkCore; |
4 | 5 |
|
5 | 6 | var builder = WebApplication.CreateBuilder(args); |
6 | 7 |
|
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 | + )); |
8 | 14 |
|
| 15 | +// SignalR |
9 | 16 | builder.Services.AddSignalR(); |
10 | 17 |
|
| 18 | +// Controllers |
11 | 19 | 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(); |
14 | 24 |
|
15 | 25 | var app = builder.Build(); |
16 | | -// Configure the HTTP request pipeline. |
| 26 | + |
| 27 | +// Swagger UI hanya di Development |
17 | 28 | if (app.Environment.IsDevelopment()) |
18 | 29 | { |
19 | | - app.MapOpenApi(); |
| 30 | + app.UseSwagger(); // JSON OpenAPI |
| 31 | + app.UseSwaggerUI(); // Swagger UI di /swagger |
20 | 32 | } |
21 | 33 |
|
| 34 | +// Middleware |
22 | 35 | app.UseHttpsRedirection(); |
23 | | - |
24 | 36 | app.UseAuthorization(); |
25 | 37 |
|
| 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 |
26 | 46 | app.MapControllers(); |
27 | 47 | app.MapHub<GameHub>("/gamehub"); |
| 48 | + |
28 | 49 | app.Run(); |
0 commit comments