fixed the program.cs and run in VC code
This commit is contained in:
@@ -4,7 +4,6 @@ using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System.Text;
|
||||
using DocumentFormat.OpenXml.Office2010.Drawing.Charts;
|
||||
using FamilyTreeAPI.Authorization;
|
||||
using FamilyTreeAPI.Entities;
|
||||
using FamilyTreeAPI.GraphQL.Query;
|
||||
@@ -14,6 +13,12 @@ using FamilyTreeAPI.Repository;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Explicitly register the base paths for Linux container execution
|
||||
builder.Configuration
|
||||
.SetBasePath(AppContext.BaseDirectory) // <-- Pulls from wherever the binary sits
|
||||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
|
||||
.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true, reloadOnChange: true)
|
||||
.AddEnvironmentVariables();
|
||||
// Add services to the container.
|
||||
#region Services
|
||||
var services = builder.Services;
|
||||
@@ -23,8 +28,10 @@ services.AddControllers();
|
||||
services.AddEndpointsApiExplorer();
|
||||
services.AddSwaggerGen();
|
||||
string skey = "Super Secret SIGN AND VERIFY JWT TOKENS";
|
||||
|
||||
|
||||
var appSettingsSection = builder.Configuration.GetSection("AppSettings");
|
||||
if (appSettingsSection != null)
|
||||
if (appSettingsSection.Exists())
|
||||
{
|
||||
services.Configure<AppSettings>(appSettingsSection);
|
||||
var appSettings = appSettingsSection.Get<AppSettings>();
|
||||
@@ -32,10 +39,13 @@ if (appSettingsSection != null)
|
||||
skey = appSettings.Secret;
|
||||
else
|
||||
{
|
||||
skey = builder.Configuration.GetValue<string>("AppSettings:Secret");
|
||||
string tkey = builder.Configuration.GetValue<string>("AppSettings:Secret") ?? string.Empty;
|
||||
if (!string.IsNullOrEmpty(tkey))
|
||||
skey = tkey;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var key = Encoding.ASCII.GetBytes(skey);
|
||||
|
||||
services.AddAuthentication(x =>
|
||||
@@ -174,6 +184,17 @@ app.Run();
|
||||
#endregion
|
||||
|
||||
/*
|
||||
|
||||
<ItemGroup>
|
||||
<Content Update="appsettings.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Update="appsettings.Development.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
https://www.youtube.com/watch?v=WQFx2m5Ub9M
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user