|
@@ -1,25 +1,37 @@
|
|
|
using WebTemplate.ServerAspects.Auth;
|
|
using WebTemplate.ServerAspects.Auth;
|
|
|
|
|
+using WebTemplate.ServerAspects.Controllers;
|
|
|
using WebTemplate.ServerAspects.Cors;
|
|
using WebTemplate.ServerAspects.Cors;
|
|
|
|
|
+using WebTemplate.ServerAspects.Json;
|
|
|
using WebTemplate.ServerAspects.Spa;
|
|
using WebTemplate.ServerAspects.Spa;
|
|
|
using WebTemplate.ServerAspects.Swagger;
|
|
using WebTemplate.ServerAspects.Swagger;
|
|
|
|
|
+using WebTemplate.ServerAspects.Validation;
|
|
|
|
|
+using WebTemplate.Status;
|
|
|
|
|
|
|
|
namespace WebTemplate;
|
|
namespace WebTemplate;
|
|
|
|
|
|
|
|
public class AppServer
|
|
public class AppServer
|
|
|
{
|
|
{
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// These are all the modules that are loaded. The order is _somewhat_ important since in many situations it is
|
|
|
|
|
+ /// relevant which configuration or middleware is applied first and the modules are applied in the order in
|
|
|
|
|
+ /// which they appear here.
|
|
|
|
|
+ /// </summary>
|
|
|
private readonly IList<IAppConfigurationModule> _modules = new List<IAppConfigurationModule>
|
|
private readonly IList<IAppConfigurationModule> _modules = new List<IAppConfigurationModule>
|
|
|
{
|
|
{
|
|
|
|
|
+ new JsonModule(),
|
|
|
new AuthModule(),
|
|
new AuthModule(),
|
|
|
new CorsModule(),
|
|
new CorsModule(),
|
|
|
- new SpaRoutingModule(),
|
|
|
|
|
new SwaggerModule(),
|
|
new SwaggerModule(),
|
|
|
- //new ApiControllersModule(),
|
|
|
|
|
|
|
+ new SpaRoutingModule(),
|
|
|
|
|
+ new ValidationModule(),
|
|
|
|
|
+ new StatusEndpointModule(),
|
|
|
|
|
+ new ControllersModule(),
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
public void Start(string[] args)
|
|
public void Start(string[] args)
|
|
|
{
|
|
{
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
- //builder.Configuration.AddJsonFile()
|
|
|
|
|
|
|
+ SetupConfiguration(builder.Configuration, builder.Environment);
|
|
|
|
|
|
|
|
foreach (var appConfigurationModule in _modules)
|
|
foreach (var appConfigurationModule in _modules)
|
|
|
{
|
|
{
|
|
@@ -29,6 +41,15 @@ public class AppServer
|
|
|
var app = builder.Build();
|
|
var app = builder.Build();
|
|
|
app.UseHttpsRedirection();
|
|
app.UseHttpsRedirection();
|
|
|
|
|
|
|
|
|
|
+ if (app.Environment.IsDevelopment())
|
|
|
|
|
+ {
|
|
|
|
|
+ app.UseDeveloperExceptionPage();
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ app.UseHsts();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
foreach (var appConfigurationModule in _modules)
|
|
foreach (var appConfigurationModule in _modules)
|
|
|
{
|
|
{
|
|
|
appConfigurationModule.ConfigureApplication(app);
|
|
appConfigurationModule.ConfigureApplication(app);
|
|
@@ -36,4 +57,9 @@ public class AppServer
|
|
|
|
|
|
|
|
app.Run();
|
|
app.Run();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private void SetupConfiguration(ConfigurationManager configuration, IWebHostEnvironment env)
|
|
|
|
|
+ {
|
|
|
|
|
+ configuration.AddJsonFile($"~/{env.ApplicationName}.json", optional: true);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|