Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow serving local environment from any address #662

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions application/AppHost/ConfigurationExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace AppHost;

public static class ConfigurationExtensions
{
public static IResourceBuilder<TDestination> WithUrlConfiguration<TDestination>(
this IResourceBuilder<TDestination> builder,
string applicationBasePath) where TDestination : IResourceWithEnvironment
{
var baseUrl = Environment.GetEnvironmentVariable("PUBLIC_URL") ?? "https://localhost:9000";

Check warning on line 9 in application/AppHost/ConfigurationExtensions.cs

View workflow job for this annotation

GitHub Actions / Build and Test

Refactor your code not to use hardcoded absolute paths or URIs. (https://rules.sonarsource.com/csharp/RSPEC-1075)

Check warning on line 9 in application/AppHost/ConfigurationExtensions.cs

View workflow job for this annotation

GitHub Actions / Build and Test

Refactor your code not to use hardcoded absolute paths or URIs. (https://rules.sonarsource.com/csharp/RSPEC-1075)

Check warning on line 9 in application/AppHost/ConfigurationExtensions.cs

View workflow job for this annotation

GitHub Actions / Build and Test

Refactor your code not to use hardcoded absolute paths or URIs. (https://rules.sonarsource.com/csharp/RSPEC-1075)

Check warning on line 9 in application/AppHost/ConfigurationExtensions.cs

View workflow job for this annotation

GitHub Actions / Build and Test

Refactor your code not to use hardcoded absolute paths or URIs. (https://rules.sonarsource.com/csharp/RSPEC-1075)

Check warning on line 9 in application/AppHost/ConfigurationExtensions.cs

View workflow job for this annotation

GitHub Actions / Build and Test

Refactor your code not to use hardcoded absolute paths or URIs. (https://rules.sonarsource.com/csharp/RSPEC-1075)

Check warning on line 9 in application/AppHost/ConfigurationExtensions.cs

View workflow job for this annotation

GitHub Actions / Build and Test

Refactor your code not to use hardcoded absolute paths or URIs. (https://rules.sonarsource.com/csharp/RSPEC-1075)

Check warning on line 9 in application/AppHost/ConfigurationExtensions.cs

View workflow job for this annotation

GitHub Actions / Build and Test

Refactor your code not to use hardcoded absolute paths or URIs. (https://rules.sonarsource.com/csharp/RSPEC-1075)

Check warning on line 9 in application/AppHost/ConfigurationExtensions.cs

View workflow job for this annotation

GitHub Actions / Build and Test

Refactor your code not to use hardcoded absolute paths or URIs. (https://rules.sonarsource.com/csharp/RSPEC-1075)
applicationBasePath = applicationBasePath.TrimEnd('/');

return builder
.WithEnvironment("PUBLIC_URL", baseUrl)
.WithEnvironment("CDN_URL", baseUrl + applicationBasePath);
}
}
2 changes: 2 additions & 0 deletions application/AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@

var accountManagementApi = builder
.AddProject<AccountManagement_Api>("account-management-api")
.WithUrlConfiguration("/account-management")
.WithReference(accountManagementDatabase)
.WithReference(azureStorage)
.WaitFor(accountManagementWorkers);
Expand All @@ -74,6 +75,7 @@

var backOfficeApi = builder
.AddProject<BackOffice_Api>("back-office-api")
.WithUrlConfiguration("/back-office")
.WithReference(backOfficeDatabase)
.WithReference(azureStorage)
.WaitFor(backOfficeWorkers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
"Api": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "development",
"PUBLIC_URL": "https://localhost:9000",
"CDN_URL": "https://localhost:9000/account-management"
"ASPNETCORE_ENVIRONMENT": "development"
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions application/back-office/Api/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
"Api": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "development",
"PUBLIC_URL": "https://localhost:9000",
"CDN_URL": "https://localhost:9000/back-office"
"ASPNETCORE_ENVIRONMENT": "development"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ private string GetContentSecurityPolicies()

if (_isDevelopment)
{
trustedHosts += " wss://localhost:* https://localhost:*";
var hostname = new Uri(PublicUrl).Host;
trustedHosts += $" wss://{hostname}:* https://{hostname}:*";
}

var contentSecurityPolicies = new[]
Expand Down
Loading