128 lines
4.2 KiB
C#
128 lines
4.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Church.Net.DAL.EF;
|
|
using Church.Net.DAL.EFCoreDBF.Core;
|
|
using Church.Net.DAL.EFCoreDBF.Interface;
|
|
using Church.Net.Entity;
|
|
using Church.Net.Entity.Games.MD2;
|
|
using Church.Net.WebAPI.Bindings;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Diagnostics;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.HttpsPolicy;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
using Newtonsoft.Json.Serialization;
|
|
using WebAPI.Handlers;
|
|
using WebAPI.Hubs;
|
|
using WebAPI.Logics;
|
|
using WebAPI.Logics.Core;
|
|
using WebAPI.Logics.Interface;
|
|
using WebAPI.Services;
|
|
using WebAPI.Services.AutoReplyCommands;
|
|
using WebAPI.Services.Interfaces;
|
|
using WebAPI.Services.ScheduledTask;
|
|
using static System.Net.Mime.MediaTypeNames;
|
|
|
|
namespace WebAPI
|
|
{
|
|
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)
|
|
{
|
|
|
|
services.AddHttpContextAccessor();
|
|
|
|
|
|
|
|
new APIBinding().Binding(services);
|
|
new LogicBinding().Binding(services);
|
|
new DALBinding().Binding(services);
|
|
|
|
}
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, DatabaseOptions databaseOptions)
|
|
{
|
|
//Reference:https://stackoverflow.com/questions/69961449/net6-and-datetime-problem-cannot-write-datetime-with-kind-utc-to-postgresql-ty
|
|
|
|
|
|
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
|
AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true);
|
|
AppDomain.CurrentDomain.SetData("ContentRootPath", env.ContentRootPath);
|
|
AppDomain.CurrentDomain.SetData("WebRootPath", env.WebRootPath);
|
|
if (env.IsDevelopment())
|
|
{
|
|
//app.UseDeveloperExceptionPage();
|
|
app.UseExceptionHandler("/error-development");
|
|
}
|
|
else
|
|
{
|
|
app.UseExceptionHandler("/error");
|
|
}
|
|
|
|
// global cors policy
|
|
app.UseCors(x => x
|
|
//.AllowAnyOrigin()
|
|
.AllowAnyMethod()
|
|
.AllowAnyHeader()
|
|
.SetIsOriginAllowed(origin => true) // allow any origin
|
|
.AllowCredentials()
|
|
); // allow credentials
|
|
|
|
|
|
|
|
//app.UseHttpsRedirection();
|
|
//app.UsePathBase(new PathString("/api"));
|
|
app.UsePathBase(new PathString("/"));
|
|
app.UseRouting();
|
|
|
|
//app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
{
|
|
//endpoints.MapControllerRoute(
|
|
// name: "default",
|
|
// pattern: "{controller}/{id?}");
|
|
endpoints.MapHub<AvalonHub>("/AvalonHub");
|
|
endpoints.MapHub<WhoIsSpyHub>("/WhoIsSpyHub");
|
|
endpoints.MapHub<BaseHub>("/BaseHub");
|
|
endpoints.MapHub<GameRoomHub>("/GameRoomHub");
|
|
|
|
endpoints.MapControllers();
|
|
|
|
//endpoints.MapControllerRoute(
|
|
// name: "default",
|
|
// pattern: "{controller}/{action=Index}/{id?}");
|
|
});
|
|
|
|
if (env.IsDevelopment())
|
|
{
|
|
databaseOptions.GetDbContext().Database.Migrate();
|
|
//new ChurchNetContext(databaseOptions.ConnectionString).Database.Migrate();
|
|
//dbContext.Database.EnsureCreated();
|
|
//dbContext.Database.Migrate();
|
|
}
|
|
}
|
|
}
|
|
}
|