From a6d68eb78b1746837744dcffc14682b36b9dfd5e Mon Sep 17 00:00:00 2001 From: kelvin Date: Sun, 17 Nov 2024 18:01:26 +0300 Subject: [PATCH] fix: attempt to fix not found page in deployed app in azure app service --- AdminHubApi/Program.cs | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/AdminHubApi/Program.cs b/AdminHubApi/Program.cs index 61554a2..9d01b77 100644 --- a/AdminHubApi/Program.cs +++ b/AdminHubApi/Program.cs @@ -21,6 +21,7 @@ builder.Services.AddSwaggerGen(option => { option.SwaggerDoc("v1", new OpenApiInfo { Title = "Admin Hub Api", Version = "v1" }); + option.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { In = ParameterLocation.Header, @@ -30,6 +31,7 @@ BearerFormat = "JWT", Scheme = "Bearer" }); + option.AddSecurityRequirement(new OpenApiSecurityRequirement { { @@ -37,11 +39,11 @@ { Reference = new OpenApiReference { - Type=ReferenceType.SecurityScheme, - Id="Bearer" + Type = ReferenceType.SecurityScheme, + Id = "Bearer" } }, - new string[]{} + new string[] { } } }); }); @@ -96,11 +98,27 @@ app.UseSwagger(); -// Configure the HTTP request pipeline. -if (app.Environment.IsDevelopment()) +app.UseSwaggerUI(options => { - app.UseSwaggerUI(); -} + options.SwaggerEndpoint("/swagger/v1/swagger.json", "Web API V1"); + + if (app.Environment.IsDevelopment()) + { + options.RoutePrefix = "swagger"; + } + else + { + options.RoutePrefix = string.Empty; + } +}); + +app.UseSwagger(); + +// // Configure the HTTP request pipeline. +// if (app.Environment.IsDevelopment()) +// { +// app.UseSwaggerUI(); +// } app.UseHttpsRedirection();