Working
This commit is contained in:
26
API/Api.cs
26
API/Api.cs
@ -1,20 +1,33 @@
|
||||
using System.Reflection;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.OpenApi;
|
||||
using SQLiteEF;
|
||||
|
||||
namespace API;
|
||||
|
||||
public class Api
|
||||
{
|
||||
private Tracker _tracker;
|
||||
public Api(string[] args)
|
||||
{
|
||||
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddControllers().AddNewtonsoftJson();
|
||||
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
||||
builder.Services.AddOpenApi();
|
||||
builder.Services.AddOpenApi(options =>
|
||||
{
|
||||
options.OpenApiVersion = OpenApiSpecVersion.OpenApi3_0;
|
||||
});
|
||||
builder.Services.AddCors(options => options.AddPolicy("AllowAll", p => p.AllowAnyOrigin().AllowAnyMethod()));
|
||||
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
builder.Services.AddDbContext<Context>();
|
||||
builder.Services.AddDbContext<Context>(options => options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection"), optionsBuilder => optionsBuilder.MigrationsAssembly(Assembly.GetAssembly(GetType())!)));
|
||||
|
||||
builder.Services.AddSingleton<Tracker>();
|
||||
SteamApiWrapper.SteamApiWrapper.SetApiKey(builder.Configuration.GetValue<string>("SteamWebApiKey")!);
|
||||
|
||||
WebApplication app = builder.Build();
|
||||
|
||||
@ -22,14 +35,17 @@ public class Api
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.MapOpenApi();
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Services.CreateScope().ServiceProvider.GetRequiredService<Context>().Database.Migrate();
|
||||
|
||||
app.Run();
|
||||
}
|
||||
|
Reference in New Issue
Block a user