mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 07:36:14 -05:00
Run formatting (#2230)
This commit is contained in:
@ -1,41 +1,40 @@
|
||||
namespace Bit.Server
|
||||
namespace Bit.Server;
|
||||
|
||||
public class Program
|
||||
{
|
||||
public class Program
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
var config = new ConfigurationBuilder()
|
||||
.AddCommandLine(args)
|
||||
.Build();
|
||||
|
||||
var builder = new WebHostBuilder()
|
||||
.UseConfiguration(config)
|
||||
.UseKestrel()
|
||||
.UseStartup<Startup>()
|
||||
.ConfigureLogging((hostingContext, logging) =>
|
||||
{
|
||||
logging.AddConsole().AddDebug();
|
||||
})
|
||||
.ConfigureKestrel((context, options) => { });
|
||||
|
||||
var contentRoot = config.GetValue<string>("contentRoot");
|
||||
if (!string.IsNullOrWhiteSpace(contentRoot))
|
||||
{
|
||||
var config = new ConfigurationBuilder()
|
||||
.AddCommandLine(args)
|
||||
.Build();
|
||||
|
||||
var builder = new WebHostBuilder()
|
||||
.UseConfiguration(config)
|
||||
.UseKestrel()
|
||||
.UseStartup<Startup>()
|
||||
.ConfigureLogging((hostingContext, logging) =>
|
||||
{
|
||||
logging.AddConsole().AddDebug();
|
||||
})
|
||||
.ConfigureKestrel((context, options) => { });
|
||||
|
||||
var contentRoot = config.GetValue<string>("contentRoot");
|
||||
if (!string.IsNullOrWhiteSpace(contentRoot))
|
||||
{
|
||||
builder.UseContentRoot(contentRoot);
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.UseContentRoot(Directory.GetCurrentDirectory());
|
||||
}
|
||||
|
||||
var webRoot = config.GetValue<string>("webRoot");
|
||||
if (string.IsNullOrWhiteSpace(webRoot))
|
||||
{
|
||||
builder.UseWebRoot(webRoot);
|
||||
}
|
||||
|
||||
var host = builder.Build();
|
||||
host.Run();
|
||||
builder.UseContentRoot(contentRoot);
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.UseContentRoot(Directory.GetCurrentDirectory());
|
||||
}
|
||||
|
||||
var webRoot = config.GetValue<string>("webRoot");
|
||||
if (string.IsNullOrWhiteSpace(webRoot))
|
||||
{
|
||||
builder.UseWebRoot(webRoot);
|
||||
}
|
||||
|
||||
var host = builder.Build();
|
||||
host.Run();
|
||||
}
|
||||
}
|
||||
|
@ -1,90 +1,89 @@
|
||||
using System.Globalization;
|
||||
using Microsoft.AspNetCore.StaticFiles;
|
||||
|
||||
namespace Bit.Server
|
||||
namespace Bit.Server;
|
||||
|
||||
public class Startup
|
||||
{
|
||||
public class Startup
|
||||
private readonly List<string> _longCachedPaths = new List<string>
|
||||
{
|
||||
private readonly List<string> _longCachedPaths = new List<string>
|
||||
{
|
||||
"/app/", "/locales/", "/fonts/", "/connectors/", "/scripts/"
|
||||
};
|
||||
private readonly List<string> _mediumCachedPaths = new List<string>
|
||||
{
|
||||
"/images/"
|
||||
};
|
||||
"/app/", "/locales/", "/fonts/", "/connectors/", "/scripts/"
|
||||
};
|
||||
private readonly List<string> _mediumCachedPaths = new List<string>
|
||||
{
|
||||
"/images/"
|
||||
};
|
||||
|
||||
public Startup()
|
||||
{
|
||||
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
|
||||
}
|
||||
public Startup()
|
||||
{
|
||||
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
|
||||
}
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddRouting();
|
||||
}
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddRouting();
|
||||
}
|
||||
|
||||
public void Configure(
|
||||
IApplicationBuilder app,
|
||||
IConfiguration configuration)
|
||||
public void Configure(
|
||||
IApplicationBuilder app,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
if (configuration.GetValue<bool?>("serveUnknown") ?? false)
|
||||
{
|
||||
if (configuration.GetValue<bool?>("serveUnknown") ?? false)
|
||||
app.UseStaticFiles(new StaticFileOptions
|
||||
{
|
||||
app.UseStaticFiles(new StaticFileOptions
|
||||
{
|
||||
ServeUnknownFileTypes = true,
|
||||
DefaultContentType = "application/octet-stream"
|
||||
});
|
||||
app.UseRouting();
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapGet("/alive",
|
||||
async context => await context.Response.WriteAsync(System.DateTime.UtcNow.ToString()));
|
||||
});
|
||||
}
|
||||
else if (configuration.GetValue<bool?>("webVault") ?? false)
|
||||
ServeUnknownFileTypes = true,
|
||||
DefaultContentType = "application/octet-stream"
|
||||
});
|
||||
app.UseRouting();
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
// TODO: This should be removed when asp.net natively support avif
|
||||
var provider = new FileExtensionContentTypeProvider { Mappings = { [".avif"] = "image/avif" } };
|
||||
endpoints.MapGet("/alive",
|
||||
async context => await context.Response.WriteAsync(System.DateTime.UtcNow.ToString()));
|
||||
});
|
||||
}
|
||||
else if (configuration.GetValue<bool?>("webVault") ?? false)
|
||||
{
|
||||
// TODO: This should be removed when asp.net natively support avif
|
||||
var provider = new FileExtensionContentTypeProvider { Mappings = { [".avif"] = "image/avif" } };
|
||||
|
||||
var options = new DefaultFilesOptions();
|
||||
options.DefaultFileNames.Clear();
|
||||
options.DefaultFileNames.Add("index.html");
|
||||
app.UseDefaultFiles(options);
|
||||
app.UseStaticFiles(new StaticFileOptions
|
||||
var options = new DefaultFilesOptions();
|
||||
options.DefaultFileNames.Clear();
|
||||
options.DefaultFileNames.Add("index.html");
|
||||
app.UseDefaultFiles(options);
|
||||
app.UseStaticFiles(new StaticFileOptions
|
||||
{
|
||||
ContentTypeProvider = provider,
|
||||
OnPrepareResponse = ctx =>
|
||||
{
|
||||
ContentTypeProvider = provider,
|
||||
OnPrepareResponse = ctx =>
|
||||
if (!ctx.Context.Request.Path.HasValue ||
|
||||
ctx.Context.Response.Headers.ContainsKey("Cache-Control"))
|
||||
{
|
||||
if (!ctx.Context.Request.Path.HasValue ||
|
||||
ctx.Context.Response.Headers.ContainsKey("Cache-Control"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
var path = ctx.Context.Request.Path.Value;
|
||||
if (_longCachedPaths.Any(ext => path.StartsWith(ext)))
|
||||
{
|
||||
// 14 days
|
||||
ctx.Context.Response.Headers.Append("Cache-Control", "max-age=1209600");
|
||||
}
|
||||
if (_mediumCachedPaths.Any(ext => path.StartsWith(ext)))
|
||||
{
|
||||
// 7 days
|
||||
ctx.Context.Response.Headers.Append("Cache-Control", "max-age=604800");
|
||||
}
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
var path = ctx.Context.Request.Path.Value;
|
||||
if (_longCachedPaths.Any(ext => path.StartsWith(ext)))
|
||||
{
|
||||
// 14 days
|
||||
ctx.Context.Response.Headers.Append("Cache-Control", "max-age=1209600");
|
||||
}
|
||||
if (_mediumCachedPaths.Any(ext => path.StartsWith(ext)))
|
||||
{
|
||||
// 7 days
|
||||
ctx.Context.Response.Headers.Append("Cache-Control", "max-age=604800");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
app.UseFileServer();
|
||||
app.UseRouting();
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
app.UseFileServer();
|
||||
app.UseRouting();
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapGet("/alive",
|
||||
async context => await context.Response.WriteAsync(System.DateTime.UtcNow.ToString()));
|
||||
});
|
||||
}
|
||||
endpoints.MapGet("/alive",
|
||||
async context => await context.Response.WriteAsync(System.DateTime.UtcNow.ToString()));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user