mirror of
https://github.com/bitwarden/server.git
synced 2025-07-02 08:32:50 -05:00
upgrade to aspnet core 3.1
This commit is contained in:
@ -13,12 +13,13 @@ using Bit.Core.Utilities;
|
||||
using IdentityModel;
|
||||
using System.Globalization;
|
||||
using Microsoft.IdentityModel.Logging;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Bit.Api
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public Startup(IHostingEnvironment env, IConfiguration configuration)
|
||||
public Startup(IWebHostEnvironment env, IConfiguration configuration)
|
||||
{
|
||||
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
|
||||
Configuration = configuration;
|
||||
@ -26,7 +27,7 @@ namespace Bit.Api
|
||||
}
|
||||
|
||||
public IConfiguration Configuration { get; private set; }
|
||||
public IHostingEnvironment Environment { get; set; }
|
||||
public IWebHostEnvironment Environment { get; set; }
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
@ -113,7 +114,7 @@ namespace Bit.Api
|
||||
{
|
||||
config.Conventions.Add(new ApiExplorerGroupConvention());
|
||||
config.Conventions.Add(new PublicApiControllersModelConvention());
|
||||
}).AddJsonOptions(options =>
|
||||
}).AddNewtonsoftJson(options =>
|
||||
{
|
||||
if(Environment.IsProduction() && Configuration["swaggerGen"] != "true")
|
||||
{
|
||||
@ -121,7 +122,7 @@ namespace Bit.Api
|
||||
}
|
||||
});
|
||||
|
||||
services.AddSwagger(globalSettings);
|
||||
//services.AddSwagger(globalSettings);
|
||||
|
||||
if(globalSettings.SelfHosted)
|
||||
{
|
||||
@ -138,8 +139,8 @@ namespace Bit.Api
|
||||
|
||||
public void Configure(
|
||||
IApplicationBuilder app,
|
||||
IHostingEnvironment env,
|
||||
IApplicationLifetime appLifetime,
|
||||
IWebHostEnvironment env,
|
||||
IHostApplicationLifetime appLifetime,
|
||||
GlobalSettings globalSettings,
|
||||
ILogger<Startup> logger)
|
||||
{
|
||||
@ -162,39 +163,43 @@ namespace Bit.Api
|
||||
// Add static files to the request pipeline.
|
||||
app.UseStaticFiles();
|
||||
|
||||
// Add routing
|
||||
app.UseRouting();
|
||||
|
||||
// Add Cors
|
||||
app.UseCors(policy => policy.SetIsOriginAllowed(h => true)
|
||||
.AllowAnyMethod().AllowAnyHeader().AllowCredentials());
|
||||
|
||||
// Add authentication to the request pipeline.
|
||||
// Add authentication and authorization to the request pipeline.
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
// Add current context
|
||||
app.UseMiddleware<CurrentContextMiddleware>();
|
||||
|
||||
// Add MVC to the request pipeline.
|
||||
app.UseMvc();
|
||||
// Add endpoints to the request pipeline.
|
||||
app.UseEndpoints(endpoints => endpoints.MapDefaultControllerRoute());
|
||||
|
||||
// Add Swagger
|
||||
if(Environment.IsDevelopment() || globalSettings.SelfHosted)
|
||||
{
|
||||
app.UseSwagger(config =>
|
||||
{
|
||||
config.RouteTemplate = "specs/{documentName}/swagger.json";
|
||||
var host = globalSettings.BaseServiceUri.Api.Replace("https://", string.Empty)
|
||||
.Replace("http://", string.Empty);
|
||||
config.PreSerializeFilters.Add((swaggerDoc, httpReq) => swaggerDoc.Host = host);
|
||||
});
|
||||
app.UseSwaggerUI(config =>
|
||||
{
|
||||
config.DocumentTitle = "Bitwarden API Documentation";
|
||||
config.RoutePrefix = "docs";
|
||||
config.SwaggerEndpoint($"{globalSettings.BaseServiceUri.Api}/specs/public/swagger.json",
|
||||
"Bitwarden Public API");
|
||||
config.OAuthClientId("accountType.id");
|
||||
config.OAuthClientSecret("secretKey");
|
||||
});
|
||||
}
|
||||
//if(Environment.IsDevelopment() || globalSettings.SelfHosted)
|
||||
//{
|
||||
// app.UseSwagger(config =>
|
||||
// {
|
||||
// config.RouteTemplate = "specs/{documentName}/swagger.json";
|
||||
// var host = globalSettings.BaseServiceUri.Api.Replace("https://", string.Empty)
|
||||
// .Replace("http://", string.Empty);
|
||||
// config.PreSerializeFilters.Add((swaggerDoc, httpReq) => swaggerDoc.Host = host);
|
||||
// });
|
||||
// app.UseSwaggerUI(config =>
|
||||
// {
|
||||
// config.DocumentTitle = "Bitwarden API Documentation";
|
||||
// config.RoutePrefix = "docs";
|
||||
// config.SwaggerEndpoint($"{globalSettings.BaseServiceUri.Api}/specs/public/swagger.json",
|
||||
// "Bitwarden Public API");
|
||||
// config.OAuthClientId("accountType.id");
|
||||
// config.OAuthClientSecret("secretKey");
|
||||
// });
|
||||
//}
|
||||
|
||||
// Log startup
|
||||
logger.LogInformation(Constants.BypassFiltersEventId, globalSettings.ProjectName + " started.");
|
||||
|
Reference in New Issue
Block a user