mirror of
https://github.com/bitwarden/server.git
synced 2024-11-25 12:45:18 +01:00
104 lines
3.3 KiB
C#
104 lines
3.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 Bit.Core.Identity;
|
|
using Microsoft.AspNetCore.Routing;
|
|
|
|
namespace Bit.Billing
|
|
{
|
|
public class Startup
|
|
{
|
|
public Startup(IConfiguration configuration)
|
|
{
|
|
Configuration = configuration;
|
|
}
|
|
|
|
public IConfiguration 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(globalSettings);
|
|
|
|
// PayPal Clients
|
|
services.AddSingleton<Utilities.PayPalClient>();
|
|
services.AddSingleton<Utilities.PayPalIpnClient>();
|
|
|
|
// BitPay Client
|
|
services.AddSingleton<BitPayClient>();
|
|
|
|
// Context
|
|
services.AddScoped<CurrentContext>();
|
|
|
|
// Identity
|
|
services.AddCustomIdentityServices(globalSettings);
|
|
//services.AddPasswordlessIdentityServices<ReadOnlyDatabaseIdentityUserStore>(globalSettings);
|
|
|
|
// Services
|
|
services.AddBaseServices();
|
|
services.AddDefaultServices(globalSettings);
|
|
|
|
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
|
|
|
// Mvc
|
|
services.AddMvc(config =>
|
|
{
|
|
config.Filters.Add(new LoggingExceptionHandlerFilterAttribute());
|
|
});
|
|
services.Configure<RouteOptions>(options => options.LowercaseUrls = true);
|
|
|
|
// Jobs service, uncomment when we have some jobs to run
|
|
// Jobs.JobsHostedService.AddJobsServices(services);
|
|
// services.AddHostedService<Jobs.JobsHostedService>();
|
|
}
|
|
|
|
public void Configure(
|
|
IApplicationBuilder app,
|
|
IHostingEnvironment env,
|
|
IApplicationLifetime appLifetime,
|
|
GlobalSettings globalSettings,
|
|
ILoggerFactory loggerFactory)
|
|
{
|
|
loggerFactory.AddSerilog(app, env, appLifetime, globalSettings, (e) =>
|
|
{
|
|
var context = e.Properties["SourceContext"].ToString();
|
|
if(e.Level == LogEventLevel.Information &&
|
|
(context.StartsWith("\"Bit.Billing.Jobs") || context.StartsWith("\"Bit.Core.Jobs")))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return e.Level >= LogEventLevel.Warning;
|
|
});
|
|
|
|
if(env.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
}
|
|
|
|
app.UseAuthentication();
|
|
app.UseStaticFiles();
|
|
app.UseMvcWithDefaultRoute();
|
|
}
|
|
}
|
|
}
|