1
0
mirror of https://github.com/bitwarden/server synced 2025-12-20 18:23:44 +00:00
Files
server/src/Core/Utilities/HostBuilderExtensions.cs
Kyle Spearrin 83e68bce06 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
2021-04-09 09:48:43 -04:00

45 lines
1.5 KiB
C#

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);
}
});
}
}
}