1
0
mirror of https://github.com/bitwarden/server.git synced 2024-12-23 17:07:42 +01:00

command config for server, serve unknown files

This commit is contained in:
Kyle Spearrin 2017-08-25 10:59:27 -04:00
parent 9932c3b599
commit cde50f4e6f
3 changed files with 36 additions and 7 deletions

View File

@ -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

View File

@ -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<Startup>();
if(args.Length > 0)
var contentRoot = config.GetValue<string>("contentRoot");
if(string.IsNullOrWhiteSpace(contentRoot))
{
builder.UseContentRoot(args[0]);
builder.UseContentRoot(contentRoot);
}
if(args.Length > 1)
var webRoot = config.GetValue<string>("webRoot");
if(string.IsNullOrWhiteSpace(webRoot))
{
builder.UseWebRoot(args[1]);
builder.UseWebRoot(webRoot);
}
var host = builder.Build();

View File

@ -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<bool?>("serveUnknown") ?? false;
if(serveUnknown)
{
app.UseStaticFiles(new StaticFileOptions
{
ServeUnknownFileTypes = true,
DefaultContentType = "application/octet-stream"
});
}
else
{
app.UseFileServer();
}
}
}
}