mirror of
https://github.com/bitwarden/server.git
synced 2025-07-02 00:22:50 -05:00
enable default appsettings for self hosted installs (#1263)
* enable default appsettings for self hosted installs * change setters to use arrow functions * fix tests * fix global settings ref
This commit is contained in:
44
src/Core/Utilities/HostBuilderExtensions.cs
Normal file
44
src/Core/Utilities/HostBuilderExtensions.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Bit.Core.Utilities
|
||||
{
|
||||
public static class HostBuilderExtensions
|
||||
{
|
||||
public static IHostBuilder ConfigureCustomAppConfiguration(this IHostBuilder hostBuilder, string[] args)
|
||||
{
|
||||
// Reload app configuration with SelfHosted overrides.
|
||||
return hostBuilder.ConfigureAppConfiguration((hostingContext, config) =>
|
||||
{
|
||||
if (Environment.GetEnvironmentVariable("globalSettings__selfHosted")?.ToLower() != "true")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var env = hostingContext.HostingEnvironment;
|
||||
|
||||
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
||||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true)
|
||||
.AddJsonFile("appsettings.SelfHosted.json", optional: true, reloadOnChange: true);
|
||||
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
var appAssembly = Assembly.Load(new AssemblyName(env.ApplicationName));
|
||||
if (appAssembly != null)
|
||||
{
|
||||
config.AddUserSecrets(appAssembly, optional: true);
|
||||
}
|
||||
}
|
||||
|
||||
config.AddEnvironmentVariables();
|
||||
|
||||
if (args != null)
|
||||
{
|
||||
config.AddCommandLine(args);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user