mirror of
https://github.com/bitwarden/server.git
synced 2024-11-29 13:25:17 +01:00
83 lines
2.3 KiB
C#
83 lines
2.3 KiB
C#
using System;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
using Bit.Core;
|
|
using Stripe;
|
|
using Bit.Core.Utilities;
|
|
using Serilog.Events;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
using Microsoft.AspNetCore.HttpOverrides;
|
|
|
|
namespace Bit.Billing
|
|
{
|
|
public class Startup
|
|
{
|
|
public Startup(IHostingEnvironment env)
|
|
{
|
|
var builder = new ConfigurationBuilder()
|
|
.AddSettingsConfiguration(env, "bitwarden-Billing");
|
|
Configuration = builder.Build();
|
|
}
|
|
|
|
public IConfigurationRoot Configuration { get; }
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
{
|
|
// Options
|
|
services.AddOptions();
|
|
|
|
// Settings
|
|
var globalSettings = services.AddGlobalSettingsServices(Configuration);
|
|
services.Configure<BillingSettings>(Configuration.GetSection("BillingSettings"));
|
|
|
|
// Stripe Billing
|
|
StripeConfiguration.SetApiKey(globalSettings.StripeApiKey);
|
|
|
|
// Repositories
|
|
services.AddSqlServerRepositories();
|
|
|
|
// Context
|
|
services.AddScoped<CurrentContext>();
|
|
|
|
// Services
|
|
services.AddBaseServices();
|
|
services.AddDefaultServices();
|
|
|
|
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
|
|
|
// Mvc
|
|
services.AddMvc();
|
|
}
|
|
|
|
public void Configure(
|
|
IApplicationBuilder app,
|
|
IHostingEnvironment env,
|
|
IApplicationLifetime appLifetime,
|
|
GlobalSettings globalSettings,
|
|
ILoggerFactory loggerFactory)
|
|
{
|
|
loggerFactory
|
|
.AddSerilog(env, appLifetime, globalSettings, (e) => e.Level >= LogEventLevel.Error)
|
|
.AddConsole()
|
|
.AddDebug();
|
|
|
|
if(env.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
}
|
|
|
|
// Forwarded headers
|
|
if(!env.IsDevelopment())
|
|
{
|
|
app.UseForwardedHeadersForAzure();
|
|
}
|
|
|
|
app.UseMvc();
|
|
}
|
|
}
|
|
}
|