web: add basic ASP.NET Core web interface

This commit is contained in:
Ske
2019-05-08 20:53:36 +02:00
parent 495edc3c5e
commit 95a7e5e821
13 changed files with 374 additions and 0 deletions

55
PluralKit.Web/Startup.cs Normal file
View 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);
}
}
}