Skip to content

Commit

Permalink
Merge pull request #4 from GamerVII-NET/dev
Browse files Browse the repository at this point in the history
Add Antiforgery and CORS policies to application
  • Loading branch information
GamerVII-NET authored Jun 9, 2024
2 parents cfc561b + 6cae355 commit efb0371
Showing 1 changed file with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@ namespace Gml.Web.Skin.Service.Core.Extensions.Application;

public static class ApplicationExtensions
{
private static string _policyName = "SkinServicePolicy";

public static WebApplicationBuilder CreateService(this WebApplicationBuilder builder)
{
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddAntiforgery();
builder.Services.AddAutoMapper(typeof(TextureMapper));

builder.Services
.AddCors(o => o.AddPolicy(_policyName, policyBuilder =>
{
policyBuilder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
}));

CheckFolders();

return builder;
Expand All @@ -32,9 +43,10 @@ public static WebApplication Run(this WebApplicationBuilder builder)

app.UseSwagger();
app.UseSwaggerUI();

app.UseCors(_policyName);
// app.UseHttpsRedirection();
app.AddRoutes();
app.UseAntiforgery();

app.Run();

Expand All @@ -45,34 +57,19 @@ private static WebApplication AddRoutes(this WebApplication app)
{
app.MapGet("/{userName}", TextureRequests.GetUserTexture);

app.MapPost("/skin/{userName}", TextureRequests.LoadSkin);
app.MapPost("/skin/{userName}", TextureRequests.LoadSkin).DisableAntiforgery();
app.MapGet("/skin/{userName}/{uuid?}", TextureRequests.GetSkin);
app.MapGet("/skin/{userName}/head/{size}", TextureRequests.GetSkinHead);
app.MapGet("/skin/{userName}/front/{size}", TextureRequests.GetSkinFront);
app.MapGet("/skin/{userName}/back/{size}", TextureRequests.GetSkinBack);
app.MapGet("/skin/{userName}/full-back/{size}", TextureRequests.GetSkinAndCloakBack);

app.MapGet("/cloak/{userName}/{uuid?}", TextureRequests.GetCloakTexture);
app.MapPost("/cloak/{userName}", TextureRequests.LoadCloak);
app.MapPost("/cloak/{userName}", TextureRequests.LoadCloak).DisableAntiforgery();;
app.MapGet("/cloak/{userName}/front/{size}", TextureRequests.GetCloak);

app.MapGet("/refresh/{userName}", TextureRequests.RefreshCache);

return app;
}
}

// app.MapGet("/weatherforecast", () =>
// {
// var forecast = Enumerable.Range(1, 5).Select(index =>
// new WeatherForecast
// (
// DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
// Random.Shared.Next(-20, 55),
// summaries[Random.Shared.Next(summaries.Length)]
// ))
// .ToArray();
// return forecast;
// })
// .WithName("GetWeatherForecast")
// .WithOpenApi();

0 comments on commit efb0371

Please sign in to comment.