mirror of
https://github.com/EggLinks/DanhengServer-OpenSource.git
synced 2026-01-02 20:26:03 +08:00
update
This commit is contained in:
@@ -6,10 +6,11 @@ using EggLink.DanhengServer.WebServer.Objects;
|
||||
using Google.Protobuf;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
namespace EggLink.DanhengServer.WebServer.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[EnableCors("AllowAll")]
|
||||
[Route("/")]
|
||||
public class DispatchRoutes
|
||||
{
|
||||
|
||||
@@ -4,9 +4,11 @@ using EggLink.DanhengServer.WebServer.Response;
|
||||
using EggLink.DanhengServer.WebServer.Server;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
namespace EggLink.DanhengServer.WebServer.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[EnableCors("AllowAll")]
|
||||
[Route("/")]
|
||||
public class MuipServerRoutes
|
||||
{
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
using EggLink.DanhengServer.Util;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace EggLink.DanhengServer.WebServer
|
||||
{
|
||||
@@ -11,12 +14,12 @@ namespace EggLink.DanhengServer.WebServer
|
||||
{
|
||||
public static void Main(string[] args, int port, string address)
|
||||
{
|
||||
BuildWebHost(args, port, address).Start();
|
||||
BuildWebHost(args, port, address).Run();
|
||||
}
|
||||
|
||||
public static IWebHost BuildWebHost(string[] args, int port, string address)
|
||||
{
|
||||
var b = WebHost.CreateDefaultBuilder(args)
|
||||
var builder = WebHost.CreateDefaultBuilder(args)
|
||||
.UseStartup<Startup>()
|
||||
.ConfigureLogging((hostingContext, logging) =>
|
||||
{
|
||||
@@ -26,19 +29,19 @@ namespace EggLink.DanhengServer.WebServer
|
||||
|
||||
if (ConfigManager.Config.HttpServer.UseSSL)
|
||||
{
|
||||
b.UseKestrel(options =>
|
||||
{
|
||||
options.Listen(IPAddress.Any, port, listenOptions =>
|
||||
{
|
||||
listenOptions.UseHttps(
|
||||
ConfigManager.Config.KeyStore.KeyStorePath,
|
||||
ConfigManager.Config.KeyStore.KeyStorePassword
|
||||
);
|
||||
});
|
||||
});
|
||||
builder.UseKestrel(options =>
|
||||
{
|
||||
options.Listen(IPAddress.Any, port, listenOptions =>
|
||||
{
|
||||
listenOptions.UseHttps(
|
||||
ConfigManager.Config.KeyStore.KeyStorePath,
|
||||
ConfigManager.Config.KeyStore.KeyStorePassword
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return b.Build();
|
||||
return builder.Build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +50,16 @@ namespace EggLink.DanhengServer.WebServer
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddControllers();
|
||||
|
||||
// Configure CORS
|
||||
services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("AllowAll",
|
||||
builder => builder
|
||||
.AllowAnyOrigin() // Allow any origin
|
||||
.AllowAnyMethod() // Allow any method (GET, POST, PUT, DELETE, etc.)
|
||||
.AllowAnyHeader()); // Allow any headers
|
||||
});
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
@@ -76,6 +89,9 @@ namespace EggLink.DanhengServer.WebServer
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
|
||||
app.UseCors("AllowAll");
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
|
||||
Reference in New Issue
Block a user