geekbot/Geekbot.net/WebApi/WebApiStartup.cs

56 lines
2.3 KiB
C#
Raw Normal View History

using System.Net;
2018-05-14 02:33:49 +02:00
using System.Reflection;
using Discord.Commands;
2018-09-02 23:59:41 +02:00
using Discord.WebSocket;
using Geekbot.net.Database;
2018-05-14 02:33:49 +02:00
using Geekbot.net.Lib;
2018-09-02 23:59:41 +02:00
using Geekbot.net.Lib.GlobalSettings;
2018-05-14 02:33:49 +02:00
using Geekbot.net.Lib.Logger;
using Geekbot.net.WebApi.Logging;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace Geekbot.net.WebApi
{
public static class WebApiStartup
2018-05-14 02:33:49 +02:00
{
public static void StartWebApi(IGeekbotLogger logger, RunParameters runParameters, CommandService commandService,
2018-09-02 23:59:41 +02:00
DatabaseContext databaseContext, DiscordSocketClient client, IGlobalSettings globalSettings)
2018-05-14 02:33:49 +02:00
{
WebHost.CreateDefaultBuilder()
.UseKestrel(options =>
{
options.Listen(IPAddress.Any, int.Parse(runParameters.ApiPort));
})
.ConfigureServices(services =>
{
services.AddMvc();
services.AddSingleton<CommandService>(commandService);
services.AddSingleton<DatabaseContext>(databaseContext);
2018-09-02 23:59:41 +02:00
services.AddSingleton<DiscordSocketClient>(client);
services.AddSingleton<IGlobalSettings>(globalSettings);
2018-05-14 02:33:49 +02:00
services.AddCors(options =>
{
options.AddPolicy("AllowSpecificOrigin",
builder => builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());
});
})
.Configure(app =>
{
app.UseMvc();
app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod().Build());
})
.ConfigureLogging(logging =>
{
logging.ClearProviders();
logging.SetMinimumLevel(LogLevel.Debug);
logging.AddProvider(new AspLogProvider(logger));
})
.UseSetting(WebHostDefaults.ApplicationKey, typeof(Program).GetTypeInfo().Assembly.FullName)
.Build().Run();
}
}
}