InitializeCorsAndHttps
This commit is contained in:
		
							
								
								
									
										6
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
								
							| @ -82,17 +82,17 @@ | |||||||
|       }, |       }, | ||||||
|       "dev": { |       "dev": { | ||||||
|         "ownerId": "5f0b1052-466d-44de-a554-226d7256850d", |         "ownerId": "5f0b1052-466d-44de-a554-226d7256850d", | ||||||
|         "host": "http://localhost:5003", |         "host": "https://localhost:5003", | ||||||
|         "token": "ey..dev", |         "token": "ey..dev", | ||||||
|       }, |       }, | ||||||
|       "affirm": { |       "affirm": { | ||||||
|         "ownerId": "5f0b1052-466d-44de-a554-226d7256850d", |         "ownerId": "5f0b1052-466d-44de-a554-226d7256850d", | ||||||
|         "host": "https://products.affirm.duckdns.org/", |         "host": "https://immich-to-slideshow.affirm.duckdns.org/", | ||||||
|         "token": "ey..affirm" |         "token": "ey..affirm" | ||||||
|       }, |       }, | ||||||
|       "phares": { |       "phares": { | ||||||
|         "ownerId": "5f0b1052-466d-44de-a554-226d7256850d", |         "ownerId": "5f0b1052-466d-44de-a554-226d7256850d", | ||||||
|         "host": "https://products.phares.duckdns.org/", |         "host": "https://immich-to-slideshow.phares.duckdns.org/", | ||||||
|         "token": "ey..phares" |         "token": "ey..phares" | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -5,6 +5,7 @@ namespace ImmichToSlideshow.Models; | |||||||
|  |  | ||||||
| public record AppSettings(string Company, | public record AppSettings(string Company, | ||||||
|                           string ConnectionString, |                           string ConnectionString, | ||||||
|  |                           string[] WithOrigins, | ||||||
|                           string WorkingDirectoryName) |                           string WorkingDirectoryName) | ||||||
| { | { | ||||||
|  |  | ||||||
|  | |||||||
| @ -8,6 +8,7 @@ public class AppSettings | |||||||
|  |  | ||||||
|     public string? Company { get; set; } |     public string? Company { get; set; } | ||||||
|     public string? ConnectionString { get; set; } |     public string? ConnectionString { get; set; } | ||||||
|  |     public string[]? WithOrigins { get; set; } | ||||||
|     public string? WorkingDirectoryName { get; set; } |     public string? WorkingDirectoryName { get; set; } | ||||||
|  |  | ||||||
|     public override string ToString() |     public override string ToString() | ||||||
| @ -38,9 +39,11 @@ public class AppSettings | |||||||
|         Models.AppSettings result; |         Models.AppSettings result; | ||||||
|         if (appSettings?.Company is null) throw new NullReferenceException(nameof(appSettings.Company)); |         if (appSettings?.Company is null) throw new NullReferenceException(nameof(appSettings.Company)); | ||||||
|         if (appSettings?.ConnectionString is null) throw new NullReferenceException(nameof(appSettings.ConnectionString)); |         if (appSettings?.ConnectionString is null) throw new NullReferenceException(nameof(appSettings.ConnectionString)); | ||||||
|  |         if (appSettings?.WithOrigins is null) throw new NullReferenceException(nameof(appSettings.WithOrigins)); | ||||||
|         if (appSettings?.WorkingDirectoryName is null) throw new NullReferenceException(nameof(appSettings.WorkingDirectoryName)); |         if (appSettings?.WorkingDirectoryName is null) throw new NullReferenceException(nameof(appSettings.WorkingDirectoryName)); | ||||||
|         result = new(appSettings.Company, |         result = new(appSettings.Company, | ||||||
|                      appSettings.ConnectionString, |                      appSettings.ConnectionString, | ||||||
|  |                      appSettings.WithOrigins, | ||||||
|                      appSettings.WorkingDirectoryName); |                      appSettings.WorkingDirectoryName); | ||||||
|         return result; |         return result; | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -15,6 +15,9 @@ public class Program | |||||||
|         _ = webApplicationBuilder.Services.AddControllers(); |         _ = webApplicationBuilder.Services.AddControllers(); | ||||||
|         _ = webApplicationBuilder.Services.AddServices(appSettings); |         _ = webApplicationBuilder.Services.AddServices(appSettings); | ||||||
|         WebApplication webApplication = webApplicationBuilder.Build(); |         WebApplication webApplication = webApplicationBuilder.Build(); | ||||||
|  |         ILogger<Program>? logger = webApplication.Services.GetRequiredService<ILogger<Program>>(); | ||||||
|  |         logger.LogInformation("Starting Web Application"); | ||||||
|  |         _ = webApplication.InitializeCorsAndHttps(appSettings); | ||||||
|         _ = webApplication.MapControllers(); |         _ = webApplication.MapControllers(); | ||||||
|         _ = webApplication.InitializeDatabase(); |         _ = webApplication.InitializeDatabase(); | ||||||
|         webApplication.Run(); |         webApplication.Run(); | ||||||
|  | |||||||
| @ -1,13 +1,20 @@ | |||||||
|  | using ImmichToSlideshow.Models; | ||||||
|  |  | ||||||
| namespace ImmichToSlideshow.RequestPipeline; | namespace ImmichToSlideshow.RequestPipeline; | ||||||
|  |  | ||||||
| public static class WebApplicationExtensions | public static class WebApplicationExtensions | ||||||
| { | { | ||||||
|  |  | ||||||
|     public static WebApplication InitializeDatabase(this WebApplication webApplication) |     public static WebApplication InitializeDatabase(this WebApplication webApplication) => | ||||||
|     { |  | ||||||
|         ILogger<Program>? logger = webApplication.Services.GetRequiredService<ILogger<Program>>(); |  | ||||||
|         logger.LogInformation("Starting Web Application"); |  | ||||||
|         // DBInitializer.Initialize(application.Configuration[DbConstants.DefaultConnectionStringPath]!); |         // DBInitializer.Initialize(application.Configuration[DbConstants.DefaultConnectionStringPath]!); | ||||||
|  |         webApplication; | ||||||
|  |  | ||||||
|  |     public static WebApplication InitializeCorsAndHttps(this WebApplication webApplication, AppSettings appSettings) | ||||||
|  |     { | ||||||
|  |         _ = webApplication.UseCors(corsPolicyBuilder => | ||||||
|  |             corsPolicyBuilder.WithOrigins(appSettings.WithOrigins).AllowAnyHeader().AllowAnyMethod()); | ||||||
|  |         _ = webApplication.UseHttpsRedirection(); | ||||||
|  |         _ = webApplication.UseHsts(); | ||||||
|         return webApplication; |         return webApplication; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user