mirror of
https://github.com/EggLinks/DanhengServer-OpenSource.git
synced 2026-01-02 20:26:03 +08:00
update
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
using EggLink.DanhengServer.Util;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System.IO;
|
||||
|
||||
namespace EggLink.DanhengServer.WebServer
|
||||
{
|
||||
@@ -14,12 +17,12 @@ namespace EggLink.DanhengServer.WebServer
|
||||
{
|
||||
public static void Main(string[] args, int port, string address)
|
||||
{
|
||||
BuildWebHost(args, port, address).Run();
|
||||
BuildWebHost(args, port, address).Start();
|
||||
}
|
||||
|
||||
public static IWebHost BuildWebHost(string[] args, int port, string address)
|
||||
{
|
||||
var builder = WebHost.CreateDefaultBuilder(args)
|
||||
var b = WebHost.CreateDefaultBuilder(args)
|
||||
.UseStartup<Startup>()
|
||||
.ConfigureLogging((hostingContext, logging) =>
|
||||
{
|
||||
@@ -29,19 +32,19 @@ namespace EggLink.DanhengServer.WebServer
|
||||
|
||||
if (ConfigManager.Config.HttpServer.UseSSL)
|
||||
{
|
||||
builder.UseKestrel(options =>
|
||||
{
|
||||
options.Listen(IPAddress.Any, port, listenOptions =>
|
||||
{
|
||||
listenOptions.UseHttps(
|
||||
ConfigManager.Config.KeyStore.KeyStorePath,
|
||||
ConfigManager.Config.KeyStore.KeyStorePassword
|
||||
);
|
||||
});
|
||||
});
|
||||
b.UseKestrel(options =>
|
||||
{
|
||||
options.Listen(IPAddress.Any, port, listenOptions =>
|
||||
{
|
||||
listenOptions.UseHttps(
|
||||
ConfigManager.Config.KeyStore.KeyStorePath,
|
||||
ConfigManager.Config.KeyStore.KeyStorePassword
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return builder.Build();
|
||||
return b.Build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,17 +52,18 @@ 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
|
||||
builder =>
|
||||
{
|
||||
builder.AllowAnyOrigin()
|
||||
.AllowAnyMethod()
|
||||
.AllowAnyHeader();
|
||||
});
|
||||
});
|
||||
|
||||
services.AddControllers();
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
@@ -89,7 +93,6 @@ namespace EggLink.DanhengServer.WebServer
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
// Enable CORS globally
|
||||
app.UseCors("AllowAll");
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
Reference in New Issue
Block a user