feat: working on models (#11)
This commit is contained in:
parent
24849b3246
commit
75e18507aa
6 changed files with 65 additions and 24 deletions
26
Program.cs
26
Program.cs
|
@ -2,34 +2,30 @@ using System.Reflection;
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Myhm.Data;
|
||||
using Myhm.Models;
|
||||
using Myhm.Util.SwaggerTheme;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Configuration
|
||||
var config = builder.Configuration.GetSection("Configuration").Get<MyhmConfiguration>();
|
||||
builder.Services.Configure<MyhmConfiguration>(builder.Configuration.GetSection("Configuration"));
|
||||
|
||||
if (config?.GlobalToken == "CHANGE-ME")
|
||||
if ((config?.AuthToken?.Length ?? 0) < 64 && !builder.Environment.IsDevelopment())
|
||||
{
|
||||
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."
|
||||
"Global token is not a valid value, please set the `CONFIGURATION__GLOBALTOKEN` environment variable to a random value of at least 64 characters. `openssl rand -hex 64` is a good way to generate a random value."
|
||||
);
|
||||
}
|
||||
|
||||
// Initialize Database
|
||||
builder.Services.AddDbContextFactory<MyhmContext>(options =>
|
||||
options.UseNpgsql(builder.Configuration.GetConnectionString("MyhmContext"))
|
||||
);
|
||||
|
||||
// Sentry
|
||||
if (config?.UseSentry == true)
|
||||
{
|
||||
builder.WebHost.UseSentry();
|
||||
}
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddHttpLogging(o => { });
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen(opts =>
|
||||
|
@ -97,11 +93,9 @@ if (config?.LogRequests == true)
|
|||
app.UseHttpLogging();
|
||||
}
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (!app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseExceptionHandler("/Error", createScopeForErrors: true);
|
||||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
||||
app.UseHsts();
|
||||
}
|
||||
|
||||
|
@ -109,12 +103,12 @@ app.UseHttpsRedirection();
|
|||
|
||||
//app.UseAntiforgery();
|
||||
|
||||
// if (app.Environment.IsDevelopment())
|
||||
// {
|
||||
// app.Logger.LogInformation(
|
||||
// "Development mode detected, printing configuration: {Configuration}",
|
||||
// config?.ToJson()
|
||||
// );
|
||||
// }
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.Logger.LogInformation(
|
||||
"Development mode detected, printing configuration: {Configuration}",
|
||||
config != null ? JsonConvert.SerializeObject(config) : "null"
|
||||
);
|
||||
}
|
||||
|
||||
app.Run();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue