Compare commits
5 commits
6ef661f2d4
...
075261de59
Author | SHA1 | Date | |
---|---|---|---|
075261de59 | |||
eb8c304020 | |||
4a6bca20bc | |||
4973464c88 | |||
e0d744ca5a |
9 changed files with 160 additions and 40 deletions
9
.vscode/extensions.json
vendored
Normal file
9
.vscode/extensions.json
vendored
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"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,3 +1,11 @@
|
||||||
{
|
{
|
||||||
"dotnet.defaultSolution": "ZenithInfo.sln"
|
"dotnet.defaultSolution": "ZenithInfo.sln",
|
||||||
|
"[csharp]": {
|
||||||
|
"editor.defaultFormatter": "csharpier.csharpier-vscode",
|
||||||
|
"editor.formatOnSave": true,
|
||||||
|
"editor.formatOnSaveMode": "file"
|
||||||
|
},
|
||||||
|
"files.associations": {
|
||||||
|
"*.json": "jsonc"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
18
Models/ZIConfiguration.cs
Normal file
18
Models/ZIConfiguration.cs
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
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,9 +1,27 @@
|
||||||
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 => { });
|
||||||
|
@ -48,8 +66,16 @@ builder.Services.AddSwaggerGen(opts =>
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
app.UseSwagger();
|
if (config?.UseSwagger == true)
|
||||||
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())
|
||||||
|
@ -66,4 +92,11 @@ 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();
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
"windowsAuthentication": false,
|
"windowsAuthentication": false,
|
||||||
"anonymousAuthentication": true,
|
"anonymousAuthentication": true,
|
||||||
"iisExpress": {
|
"iisExpress": {
|
||||||
"applicationUrl": "http://localhost:7739",
|
"applicationUrl": "http://localhost:48070",
|
||||||
"sslPort": 44309
|
"sslPort": 44382
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"profiles": {
|
"profiles": {
|
||||||
|
@ -13,7 +13,8 @@
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"dotnetRunMessages": true,
|
"dotnetRunMessages": true,
|
||||||
"launchBrowser": true,
|
"launchBrowser": true,
|
||||||
"applicationUrl": "http://localhost:5123",
|
"launchUrl": "swagger",
|
||||||
|
"applicationUrl": "http://localhost:5150",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
}
|
}
|
||||||
|
@ -22,7 +23,8 @@
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"dotnetRunMessages": true,
|
"dotnetRunMessages": true,
|
||||||
"launchBrowser": true,
|
"launchBrowser": true,
|
||||||
"applicationUrl": "https://localhost:7268;http://localhost:5123",
|
"launchUrl": "swagger",
|
||||||
|
"applicationUrl": "https://localhost:7047;http://localhost:5150",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
}
|
}
|
||||||
|
@ -30,9 +32,10 @@
|
||||||
"IIS Express": {
|
"IIS Express": {
|
||||||
"commandName": "IISExpress",
|
"commandName": "IISExpress",
|
||||||
"launchBrowser": true,
|
"launchBrowser": true,
|
||||||
|
"launchUrl": "swagger",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
26
Util/RandomStringGenerator.cs
Normal file
26
Util/RandomStringGenerator.cs
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
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,6 +10,7 @@
|
||||||
</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,8 +1,12 @@
|
||||||
{
|
{
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Information",
|
"Default": "Trace"
|
||||||
"Microsoft.AspNetCore": "Warning"
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"Configuration": {
|
||||||
|
// DO NOT USE THIS AUTHTOKEN IN PRODUCTION!!!
|
||||||
|
"AuthToken": "hi",
|
||||||
|
"UseSentry": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,26 @@
|
||||||
"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