Compare commits
No commits in common. "075261de5985ac35e9c688a7fb2506d959922174" and "6ef661f2d458d3d0560a7677a2993380c3b90612" have entirely different histories.
075261de59
...
6ef661f2d4
9 changed files with 40 additions and 160 deletions
9
.vscode/extensions.json
vendored
9
.vscode/extensions.json
vendored
|
@ -1,9 +0,0 @@
|
||||||
{
|
|
||||||
"recommendations": [
|
|
||||||
"ms-dotnettools.csharp",
|
|
||||||
"ms-dotnettools.vscodeintellicode-csharp",
|
|
||||||
"csharpier.csharpier-vscode",
|
|
||||||
"patcx.vscode-nuget-gallery",
|
|
||||||
"vasubasraj.flashpost"
|
|
||||||
]
|
|
||||||
}
|
|
10
.vscode/settings.json
vendored
10
.vscode/settings.json
vendored
|
@ -1,11 +1,3 @@
|
||||||
{
|
{
|
||||||
"dotnet.defaultSolution": "ZenithInfo.sln",
|
"dotnet.defaultSolution": "ZenithInfo.sln"
|
||||||
"[csharp]": {
|
|
||||||
"editor.defaultFormatter": "csharpier.csharpier-vscode",
|
|
||||||
"editor.formatOnSave": true,
|
|
||||||
"editor.formatOnSaveMode": "file"
|
|
||||||
},
|
|
||||||
"files.associations": {
|
|
||||||
"*.json": "jsonc"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
namespace ZenithInfo.Models
|
|
||||||
{
|
|
||||||
public class ZIConfiguration
|
|
||||||
{
|
|
||||||
public required string GlobalToken { get; init; }
|
|
||||||
public string? DatabaseConnectionString { get; init; } = null;
|
|
||||||
public DatabaseTypes DatabaseType { get; init; } = DatabaseTypes.Memory;
|
|
||||||
public bool UseSentry { get; init; } = true;
|
|
||||||
public bool UseSwagger { get; init; } = true;
|
|
||||||
public bool LogRequests { get; init; } = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum DatabaseTypes
|
|
||||||
{
|
|
||||||
Memory,
|
|
||||||
PostgresSQL,
|
|
||||||
}
|
|
||||||
}
|
|
37
Program.cs
37
Program.cs
|
@ -1,27 +1,9 @@
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
using ZenithInfo.Components;
|
using ZenithInfo.Components;
|
||||||
using ZenithInfo.Models;
|
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
// Configuration
|
|
||||||
var config = builder.Configuration.GetSection("Configuration").Get<ZIConfiguration>();
|
|
||||||
builder.Services.Configure<ZIConfiguration>(builder.Configuration.GetSection("Configuration"));
|
|
||||||
|
|
||||||
if (config?.GlobalToken == "CHANGE-ME")
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException(
|
|
||||||
"Global token is not a valid value, please set the `CONFIGURATION__GLOBALTOKEN` environment variable to a random value. `openssl rand -hex 64` is a good way to generate a random value."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sentry
|
|
||||||
if (config?.UseSentry == true)
|
|
||||||
{
|
|
||||||
builder.WebHost.UseSentry();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
builder.Services.AddRazorComponents().AddInteractiveServerComponents();
|
builder.Services.AddRazorComponents().AddInteractiveServerComponents();
|
||||||
builder.Services.AddHttpLogging(o => { });
|
builder.Services.AddHttpLogging(o => { });
|
||||||
|
@ -66,16 +48,8 @@ builder.Services.AddSwaggerGen(opts =>
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
if (config?.UseSwagger == true)
|
app.UseSwagger();
|
||||||
{
|
app.UseSwaggerUI();
|
||||||
app.UseSwagger();
|
|
||||||
app.UseSwaggerUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config?.LogRequests == true)
|
|
||||||
{
|
|
||||||
app.UseHttpLogging();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
if (!app.Environment.IsDevelopment())
|
if (!app.Environment.IsDevelopment())
|
||||||
|
@ -92,11 +66,4 @@ app.UseAntiforgery();
|
||||||
|
|
||||||
app.MapRazorComponents<App>().AddInteractiveServerRenderMode();
|
app.MapRazorComponents<App>().AddInteractiveServerRenderMode();
|
||||||
|
|
||||||
if (config?.DatabaseType == DatabaseTypes.Memory)
|
|
||||||
{
|
|
||||||
app.Logger.LogWarning(
|
|
||||||
"`Memory` database type is in use. Data will be lost when the application is restarted. If you are not in a development environment, you should use `PostgresSQL` instead."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|
|
@ -1,41 +1,38 @@
|
||||||
{
|
{
|
||||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||||
"iisSettings": {
|
"iisSettings": {
|
||||||
"windowsAuthentication": false,
|
"windowsAuthentication": false,
|
||||||
"anonymousAuthentication": true,
|
"anonymousAuthentication": true,
|
||||||
"iisExpress": {
|
"iisExpress": {
|
||||||
"applicationUrl": "http://localhost:48070",
|
"applicationUrl": "http://localhost:7739",
|
||||||
"sslPort": 44382
|
"sslPort": 44309
|
||||||
}
|
|
||||||
},
|
|
||||||
"profiles": {
|
|
||||||
"http": {
|
|
||||||
"commandName": "Project",
|
|
||||||
"dotnetRunMessages": true,
|
|
||||||
"launchBrowser": true,
|
|
||||||
"launchUrl": "swagger",
|
|
||||||
"applicationUrl": "http://localhost:5150",
|
|
||||||
"environmentVariables": {
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"https": {
|
"profiles": {
|
||||||
"commandName": "Project",
|
"http": {
|
||||||
"dotnetRunMessages": true,
|
"commandName": "Project",
|
||||||
"launchBrowser": true,
|
"dotnetRunMessages": true,
|
||||||
"launchUrl": "swagger",
|
"launchBrowser": true,
|
||||||
"applicationUrl": "https://localhost:7047;http://localhost:5150",
|
"applicationUrl": "http://localhost:5123",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"IIS Express": {
|
"https": {
|
||||||
"commandName": "IISExpress",
|
"commandName": "Project",
|
||||||
"launchBrowser": true,
|
"dotnetRunMessages": true,
|
||||||
"launchUrl": "swagger",
|
"launchBrowser": true,
|
||||||
"environmentVariables": {
|
"applicationUrl": "https://localhost:7268;http://localhost:5123",
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"IIS Express": {
|
||||||
|
"commandName": "IISExpress",
|
||||||
|
"launchBrowser": true,
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
using System.Security.Cryptography;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace ZenithInfo.Util;
|
|
||||||
|
|
||||||
public class RandomStringGenerator
|
|
||||||
{
|
|
||||||
private static readonly char[] chars =
|
|
||||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*+?".ToCharArray();
|
|
||||||
|
|
||||||
public static string GenerateRandomString(int length)
|
|
||||||
{
|
|
||||||
var stringBuilder = new StringBuilder();
|
|
||||||
using (var rng = RandomNumberGenerator.Create())
|
|
||||||
{
|
|
||||||
byte[] buffer = new byte[1];
|
|
||||||
for (int i = 0; i < length; i++)
|
|
||||||
{
|
|
||||||
rng.GetBytes(buffer);
|
|
||||||
var randomIndex = buffer[0] % chars.Length;
|
|
||||||
stringBuilder.Append(chars[randomIndex]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return stringBuilder.ToString();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -10,7 +10,6 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Sentry.AspNetCore" Version="5.0.0" />
|
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.2.0" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.2.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,8 @@
|
||||||
{
|
{
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Trace"
|
"Default": "Information",
|
||||||
}
|
"Microsoft.AspNetCore": "Warning"
|
||||||
},
|
}
|
||||||
"Configuration": {
|
|
||||||
// DO NOT USE THIS AUTHTOKEN IN PRODUCTION!!!
|
|
||||||
"AuthToken": "hi",
|
|
||||||
"UseSentry": false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,26 +2,8 @@
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Information",
|
"Default": "Information",
|
||||||
"Microsoft.AspNetCore": "Warning",
|
"Microsoft.AspNetCore": "Warning"
|
||||||
"Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware": "Information"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*"
|
||||||
"Configuration": {
|
|
||||||
"AuthToken": "CHANGE-ME",
|
|
||||||
"UseSwagger": true,
|
|
||||||
"LogRequests": true,
|
|
||||||
"UseSentry": true
|
|
||||||
},
|
|
||||||
"Sentry": {
|
|
||||||
"Dsn": "https://92b5c863371d9362c50a39b3faccd26d@sentry.csw.im/5",
|
|
||||||
"SendDefaultPii": true,
|
|
||||||
"MaxRequestBodySize": "Always",
|
|
||||||
"MinimumBreadcrumbLevel": "Debug",
|
|
||||||
"MinimumEventLevel": "Warning",
|
|
||||||
"AttachStackTrace": true,
|
|
||||||
"Debug": true,
|
|
||||||
"DiagnosticLevel": "Error",
|
|
||||||
"TracesSampleRate": 1.0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue