|
29 | 29 | var appHostname = app.Configuration["Hostnames:App"] ?? "app.unconfigured.invalid"; |
30 | 30 | var backOfficeHostname = app.Services.GetRequiredService<IOptions<BackOfficeHostOptions>>().Value.Host; |
31 | 31 |
|
| 32 | +// Per-host bundle URLs. The process-wide PUBLIC_URL/CDN_URL env vars are set by AppHost for the |
| 33 | +// user-facing host only, so the back-office host must inject its own to avoid embedding the account |
| 34 | +// SPA's bundle URLs into back-office HTML. |
| 35 | +var appPublicUrl = Environment.GetEnvironmentVariable(SinglePageAppConfiguration.PublicUrlKey); |
| 36 | +var appCdnUrl = Environment.GetEnvironmentVariable(SinglePageAppConfiguration.CdnUrlKey); |
| 37 | +var backOfficePublicUrl = appPublicUrl is null ? null : ReplaceHost(appPublicUrl, appHostname, backOfficeHostname); |
| 38 | +var backOfficeCdnUrl = backOfficePublicUrl; |
| 39 | + |
32 | 40 | app |
33 | 41 | .UseApiServices() // Add common configuration for all APIs like Swagger, HSTS, and DeveloperExceptionPage. |
34 | 42 | .UseHostScopedSinglePageAppFallback( |
35 | 43 | new HostScopedSinglePageApp( |
36 | 44 | appHostname, |
37 | 45 | "WebApp", |
38 | | - context => context.RequestServices.GetRequiredService<IExecutionContext>().UserInfo |
| 46 | + context => context.RequestServices.GetRequiredService<IExecutionContext>().UserInfo, |
| 47 | + appPublicUrl, |
| 48 | + appCdnUrl |
39 | 49 | ), |
40 | 50 | new HostScopedSinglePageApp( |
41 | 51 | backOfficeHostname, |
42 | 52 | "BackOfficeWebApp", |
43 | | - BuildBackOfficeUserInfo |
| 53 | + BuildBackOfficeUserInfo, |
| 54 | + backOfficePublicUrl, |
| 55 | + backOfficeCdnUrl, |
| 56 | + BackOfficeIdentityDefaults.PolicyName |
44 | 57 | ) |
45 | 58 | ); |
46 | 59 |
|
47 | 60 | await app.RunAsync(); |
48 | 61 | return; |
49 | 62 |
|
| 63 | +static string ReplaceHost(string url, string oldHost, string newHost) |
| 64 | +{ |
| 65 | + var uri = new Uri(url); |
| 66 | + var builder = new UriBuilder(uri) { Host = uri.Host.Equals(oldHost, StringComparison.OrdinalIgnoreCase) ? newHost : uri.Host }; |
| 67 | + return builder.Uri.ToString().TrimEnd('/'); |
| 68 | +} |
| 69 | + |
50 | 70 | static UserInfo BuildBackOfficeUserInfo(HttpContext context) |
51 | 71 | { |
52 | 72 | var principal = context.User; |
|
0 commit comments