Skip to content

Commit 223525e

Browse files
HubService: use/store default kestrel config
1 parent d0cf8b2 commit 223525e

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

src/Certify.Server/Certify.Server.HubService/Certify.Server.HubService.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
<PackageReference Include="System.Text.Encodings.Web" Version="9.0.4" />
2424
</ItemGroup>
2525

26-
<ItemGroup>
27-
<ContainerPort Include="8081" />
28-
</ItemGroup>
29-
3026
<ItemGroup>
3127
<ProjectReference Include="..\..\Certify.Aspire\Certify.Aspire.ServiceDefaults\Certify.Aspire.ServiceDefaults.csproj" />
3228
<ProjectReference Include="..\..\Certify.Shared\Certify.Shared.Core.csproj" />

src/Certify.Server/Certify.Server.HubService/Program.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,25 @@
4040

4141
var builder = WebApplication.CreateBuilder(args);
4242

43+
// allow settings to be loaded from the app data path, that way settings are preserved between re-installs, copy a default config so service starts on localhost:8080
44+
var settingsPath = EnvironmentUtil.EnsuredAppDataPath();
45+
var hubSettings = Path.Combine(settingsPath, "hub-service.json");
46+
var defaultHubSettings = Path.Combine(cwd, "default-settings.json");
47+
48+
#if !DEBUG
49+
if (!File.Exists(hubSettings) && File.Exists(defaultHubSettings))
50+
{
51+
// copy default config if it doesn't exist
52+
File.Copy(
53+
defaultHubSettings,
54+
hubSettings,
55+
false
56+
);
57+
}
58+
#endif
59+
60+
builder.Configuration.AddJsonFile(hubSettings, optional: true, reloadOnChange: true);
61+
4362
// if windows, run as service, otherwise run as console app
4463
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
4564
{
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft": "Warning",
6+
"Microsoft.Hosting.Lifetime": "Information"
7+
}
8+
},
9+
"Kestrel": {
10+
"Endpoints": {
11+
"SvcHttpEndpoint": {
12+
"Url": "http://0.0.0.0:8080"
13+
}
14+
// exmaple HTTP config. Before using, acquire a certificate for desired host e.g. certifyhub.intranet.yourdomain.com
15+
// Then add a Deployment Task (Export Certificate) to export pfx to where it's required e.g. C:\ProgramData\certify\internal-certs\hub.pfx , then run the task to export the initial certificate.
16+
// the choice of port and filename etc is arbitrary, as long as the process can access the file.
17+
// https://learn.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel/endpoints?view=aspnetcore-9.0
18+
/*
19+
"HttpsInlineCertFile": {
20+
"Url": "https://0.0.0.0:9697",
21+
"Certificate": {
22+
"Path": "C:\\ProgramData\\certify\\internal-certs\\hub.pfx",
23+
"Password": ""
24+
}
25+
}
26+
*/
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)