From cde50f4e6f97e3adeba4da4fd7e7298dca53109a Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 25 Aug 2017 10:59:27 -0400 Subject: [PATCH] command config for server, serve unknown files --- util/Attachments/entrypoint.sh | 2 +- util/Server/Program.cs | 16 ++++++++++++---- util/Server/Startup.cs | 25 +++++++++++++++++++++++-- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/util/Attachments/entrypoint.sh b/util/Attachments/entrypoint.sh index 6195ff8c3..2561b22f8 100644 --- a/util/Attachments/entrypoint.sh +++ b/util/Attachments/entrypoint.sh @@ -1,3 +1,3 @@ #!/bin/sh -dotnet /bitwarden_server/Server.dll /etc/bitwarden/core/attachments . +dotnet /bitwarden_server/Server.dll /contentRoot=/etc/bitwarden/core/attachments /webRoot=. /serveUnknown=true diff --git a/util/Server/Program.cs b/util/Server/Program.cs index 52e9e1ceb..9669d9bfe 100644 --- a/util/Server/Program.cs +++ b/util/Server/Program.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; namespace Server { @@ -6,18 +7,25 @@ namespace Server { public static void Main(string[] args) { + var config = new ConfigurationBuilder() + .AddCommandLine(args) + .Build(); + var builder = new WebHostBuilder() + .UseConfiguration(config) .UseKestrel() .UseStartup(); - if(args.Length > 0) + var contentRoot = config.GetValue("contentRoot"); + if(string.IsNullOrWhiteSpace(contentRoot)) { - builder.UseContentRoot(args[0]); + builder.UseContentRoot(contentRoot); } - if(args.Length > 1) + var webRoot = config.GetValue("webRoot"); + if(string.IsNullOrWhiteSpace(webRoot)) { - builder.UseWebRoot(args[1]); + builder.UseWebRoot(webRoot); } var host = builder.Build(); diff --git a/util/Server/Startup.cs b/util/Server/Startup.cs index 4992d5b2f..8305f47c2 100644 --- a/util/Server/Startup.cs +++ b/util/Server/Startup.cs @@ -1,5 +1,7 @@ using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; namespace Server { @@ -8,9 +10,28 @@ namespace Server public void ConfigureServices(IServiceCollection services) { } - public void Configure(IApplicationBuilder app) + public void Configure( + IApplicationBuilder app, + ILoggerFactory loggerFactory, + IConfiguration configuration) { - app.UseFileServer(); + loggerFactory + .AddConsole() + .AddDebug(); + + var serveUnknown = configuration.GetValue("serveUnknown") ?? false; + if(serveUnknown) + { + app.UseStaticFiles(new StaticFileOptions + { + ServeUnknownFileTypes = true, + DefaultContentType = "application/octet-stream" + }); + } + else + { + app.UseFileServer(); + } } } }