web: add basic ASP.NET Core web interface
This commit is contained in:
55
PluralKit.Web/Startup.cs
Normal file
55
PluralKit.Web/Startup.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System.Data;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Npgsql;
|
||||
|
||||
namespace PluralKit.Web
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public Startup(IConfiguration configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
var config = Configuration.GetSection("PluralKit").Get<CoreConfig>();
|
||||
|
||||
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
|
||||
|
||||
services
|
||||
.AddSingleton<IDbConnection, NpgsqlConnection>(_ => new NpgsqlConnection(config.Database))
|
||||
.AddSingleton<SystemStore>()
|
||||
.AddSingleton<MemberStore>()
|
||||
.AddSingleton(config);
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public async void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
||||
{
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
else
|
||||
{
|
||||
app.UseExceptionHandler("/Error");
|
||||
}
|
||||
|
||||
//app.UseHttpsRedirection();
|
||||
app.UseMvc();
|
||||
|
||||
var conn = app.ApplicationServices.GetRequiredService<IDbConnection>();
|
||||
conn.Open();
|
||||
|
||||
await Schema.CreateTables(conn);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user