2018-05-15 01:18:26 +02:00
|
|
|
|
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;
|
2018-05-15 01:18:26 +02:00
|
|
|
|
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-09-05 22:55:45 +02:00
|
|
|
|
using Geekbot.net.Lib.Highscores;
|
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
|
|
|
|
|
{
|
2018-05-15 01:18:26 +02:00
|
|
|
|
public static class WebApiStartup
|
2018-05-14 02:33:49 +02:00
|
|
|
|
{
|
2018-05-15 01:18:26 +02:00
|
|
|
|
public static void StartWebApi(IGeekbotLogger logger, RunParameters runParameters, CommandService commandService,
|
2018-09-05 22:55:45 +02:00
|
|
|
|
DatabaseContext databaseContext, DiscordSocketClient client, IGlobalSettings globalSettings, IHighscoreManager highscoreManager)
|
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);
|
2018-05-15 01:18:26 +02:00
|
|
|
|
services.AddSingleton<DatabaseContext>(databaseContext);
|
2018-09-02 23:59:41 +02:00
|
|
|
|
services.AddSingleton<DiscordSocketClient>(client);
|
|
|
|
|
services.AddSingleton<IGlobalSettings>(globalSettings);
|
2018-09-05 22:55:45 +02:00
|
|
|
|
services.AddSingleton<IHighscoreManager>(highscoreManager);
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|