Skip to content

Commit f4e332e

Browse files
committed
Add production appsettings and prod config guard for Playground
1 parent d4c6a03 commit f4e332e

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-0
lines changed

src/Playground/Playground.Api/Program.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@
1111

1212
var builder = WebApplication.CreateBuilder(args);
1313

14+
if (builder.Environment.IsProduction())
15+
{
16+
static void Require(IConfiguration config, string key)
17+
{
18+
if (string.IsNullOrWhiteSpace(config[key]))
19+
{
20+
throw new InvalidOperationException($"Missing required configuration '{key}' in Production.");
21+
}
22+
}
23+
24+
var config = builder.Configuration;
25+
Require(config, "DatabaseOptions:ConnectionString");
26+
Require(config, "CachingOptions:Redis");
27+
Require(config, "JwtOptions:SigningKey");
28+
}
29+
1430
builder.Services.AddMediator(o =>
1531
{
1632
o.ServiceLifetime = ServiceLifetime.Scoped;
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
{
2+
"OpenTelemetryOptions": {
3+
"Enabled": true,
4+
"Tracing": { "Enabled": true },
5+
"Metrics": { "Enabled": true },
6+
"Exporter": {
7+
"Otlp": {
8+
"Enabled": false,
9+
"Endpoint": "",
10+
"Protocol": "grpc"
11+
}
12+
},
13+
"Jobs": { "Enabled": true },
14+
"Mediator": { "Enabled": true },
15+
"Http": { "Histograms": { "Enabled": true } },
16+
"Data": { "FilterEfStatements": true, "FilterRedisCommands": true }
17+
},
18+
"Serilog": {
19+
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.OpenTelemetry" ],
20+
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId", "WithCorrelationId", "WithProcessId", "WithProcessName" ],
21+
"MinimumLevel": { "Default": "Information" },
22+
"WriteTo": [
23+
{ "Name": "Console", "Args": { "restrictedToMinimumLevel": "Information" } },
24+
{ "Name": "OpenTelemetry", "Args": { "endpoint": "", "protocol": "grpc", "resourceAttributes": { "service.name": "Playground.Api" } } }
25+
]
26+
},
27+
"Logging": {
28+
"LogLevel": {
29+
"Default": "Information",
30+
"Microsoft.AspNetCore": "Warning",
31+
"Hangfire": "Warning",
32+
"Microsoft.EntityFrameworkCore": "Warning"
33+
}
34+
},
35+
"DatabaseOptions": {
36+
"Provider": "POSTGRESQL",
37+
"ConnectionString": ""
38+
},
39+
"OriginOptions": {
40+
"OriginUrl": ""
41+
},
42+
"CachingOptions": {
43+
"Redis": ""
44+
},
45+
"HangfireOptions": {
46+
"Username": "",
47+
"Password": "",
48+
"Route": "/jobs"
49+
},
50+
"AllowedHosts": "api.example.com",
51+
"OpenApiOptions": {
52+
"Enabled": false,
53+
"Title": "FSH PlayGround API",
54+
"Version": "v1",
55+
"Description": "The FSH Starter Kit API for Modular/Multitenant Architecture.",
56+
"Contact": { "Name": "Mukesh Murugan", "Url": "https://codewithmukesh.com", "Email": "[email protected]" },
57+
"License": { "Name": "MIT License", "Url": "https://opensource.org/licenses/MIT" }
58+
},
59+
"CorsOptions": {
60+
"AllowAll": false,
61+
"AllowedOrigins": [],
62+
"AllowedHeaders": [ "content-type", "authorization" ],
63+
"AllowedMethods": [ "GET", "POST", "PUT", "DELETE" ]
64+
},
65+
"JwtOptions": {
66+
"Issuer": "fsh.local",
67+
"Audience": "fsh.clients",
68+
"SigningKey": "",
69+
"AccessTokenMinutes": 60,
70+
"RefreshTokenDays": 7
71+
},
72+
"MailOptions": {
73+
"From": "",
74+
"Host": "",
75+
"Port": 0,
76+
"UserName": "",
77+
"Password": "",
78+
"DisplayName": ""
79+
},
80+
"RateLimitingOptions": {
81+
"Enabled": true,
82+
"Global": { "PermitLimit": 100, "WindowSeconds": 60, "QueueLimit": 0 },
83+
"Auth": { "PermitLimit": 10, "WindowSeconds": 60, "QueueLimit": 0 }
84+
},
85+
"MultitenancyOptions": {
86+
"RunTenantMigrationsOnStartup": false
87+
},
88+
"Storage": {
89+
"Provider": "local"
90+
}
91+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
},
8+
"AllowedHosts": "ui.example.com",
9+
"Api": {
10+
"BaseUrl": ""
11+
}
12+
}

0 commit comments

Comments
 (0)