mirror of
https://git.lewd.wtf/PGR/ascnet
synced 2025-12-12 21:04:44 +01:00
Add project files.
This commit is contained in:
23
AscNet.SDKServer/AscNet.SDKServer.csproj
Normal file
23
AscNet.SDKServer/AscNet.SDKServer.csproj
Normal file
@@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<OutputType>Library</OutputType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AscNet.Common\AscNet.Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Models\" />
|
||||
<Folder Include="Properties\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
10
AscNet.SDKServer/Controllers/AccountController.cs
Normal file
10
AscNet.SDKServer/Controllers/AccountController.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace AscNet.SDKServer.Controllers
|
||||
{
|
||||
public class AccountController : IRegisterable
|
||||
{
|
||||
public static void Register(WebApplication app)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
10
AscNet.SDKServer/Controllers/ConfigController.cs
Normal file
10
AscNet.SDKServer/Controllers/ConfigController.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace AscNet.SDKServer.Controllers
|
||||
{
|
||||
internal class ConfigController : IRegisterable
|
||||
{
|
||||
public static void Register(WebApplication app)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
12
AscNet.SDKServer/Properties/launchSettings.json
Normal file
12
AscNet.SDKServer/Properties/launchSettings.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"profiles": {
|
||||
"AscNet.SDKServer": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"applicationUrl": "https://localhost:52155;http://localhost:52156"
|
||||
}
|
||||
}
|
||||
}
|
||||
66
AscNet.SDKServer/SDKServer.cs
Normal file
66
AscNet.SDKServer/SDKServer.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
namespace AscNet.SDKServer
|
||||
{
|
||||
public class SDKServer
|
||||
{
|
||||
public static readonly Common.Util.Logger c = new(nameof(SDKServer), ConsoleColor.Green);
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Disables default logger
|
||||
builder.Logging.ClearProviders();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.Urls.Add("http://*:80");
|
||||
app.Urls.Add("https://*:443");
|
||||
|
||||
IEnumerable<Type> controllers = AppDomain.CurrentDomain.GetAssemblies()
|
||||
.SelectMany(s => s.GetTypes())
|
||||
.Where(p => typeof(IRegisterable).IsAssignableFrom(p) && !p.IsInterface)
|
||||
.Select(x => x);
|
||||
|
||||
foreach (Type controller in controllers)
|
||||
{
|
||||
controller.GetMethod(nameof(IRegisterable.Register))!.Invoke(null, new object[] { app });
|
||||
#if DEBUG
|
||||
c.Log($"Registered HTTP controller '{controller.Name}'");
|
||||
#endif
|
||||
}
|
||||
|
||||
app.UseMiddleware<RequestLoggingMiddleware>();
|
||||
|
||||
new Thread(() => app.Run()).Start();
|
||||
c.Log($"{nameof(SDKServer)} started in port {string.Join(", ", app.Urls.Select(x => x.Split(':').Last()))}!");
|
||||
}
|
||||
|
||||
private class RequestLoggingMiddleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
private static readonly string[] SurpressedRoutes = new string[] { "/report", "/sdk/dataUpload" };
|
||||
|
||||
public RequestLoggingMiddleware(RequestDelegate next)
|
||||
{
|
||||
_next = next;
|
||||
}
|
||||
|
||||
public async Task Invoke(HttpContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _next(context);
|
||||
}
|
||||
finally
|
||||
{
|
||||
c.Log($"{context.Response.StatusCode} {context.Request.Method.ToUpper()} {context.Request.Path + context.Request.QueryString}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface IRegisterable
|
||||
{
|
||||
public abstract static void Register(WebApplication app);
|
||||
}
|
||||
}
|
||||
8
AscNet.SDKServer/appsettings.Development.json
Normal file
8
AscNet.SDKServer/appsettings.Development.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
9
AscNet.SDKServer/appsettings.json
Normal file
9
AscNet.SDKServer/appsettings.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
Reference in New Issue
Block a user