BotSharp/src/Infrastructure/BotSharp.OpenAPI/BotSharpOpenApiExtensions.cs

56 lines
1.4 KiB
C#
Raw Normal View History

2024-01-10 14:18:59 +00:00
using Microsoft.AspNetCore.Builder;
2023-12-19 13:16:43 +00:00
namespace BotSharp.OpenAPI;
public static class BotSharpOpenApiExtensions
{
2024-01-10 14:18:59 +00:00
/// <summary>
/// Use Swagger/OpenAPI
/// </summary>
/// <param name="services"></param>
/// <param name="config"></param>
/// <returns></returns>
public static IApplicationBuilder UseBotSharpOpenAPI(this IApplicationBuilder app, bool isDevelopment = false)
2023-12-19 13:16:43 +00:00
{
2024-01-10 14:18:59 +00:00
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
app.UseSwagger();
if (isDevelopment)
{
app.UseSwaggerUI();
}
return app;
}
2023-12-19 13:16:43 +00:00
2024-01-10 14:18:59 +00:00
/// <summary>
/// Host BotSharp UI built in adapter-static
/// </summary>
/// <param name="app"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public static IApplicationBuilder UseBotSharpUI(this IApplicationBuilder app, bool isDevelopment = false)
{
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
2023-12-19 13:16:43 +00:00
2024-01-10 14:18:59 +00:00
// app.UseFileServer();
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseSpa(config =>
{
if (isDevelopment)
{
config.UseProxyToSpaDevelopmentServer("http://localhost:5015");
}
});
2023-12-19 13:16:43 +00:00
2024-01-10 14:18:59 +00:00
return app;
2023-12-19 13:16:43 +00:00
}
}