2018-04-08 01:44:42 -05:00
|
|
|
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
2018-02-21 19:29:23 -06:00
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
2019-02-16 17:18:50 -06:00
|
|
|
|
using Microsoft.AspNetCore.Mvc.ApplicationParts;
|
2018-05-28 20:30:31 -05:00
|
|
|
|
using Microsoft.AspNetCore.Mvc.Razor;
|
2018-02-21 19:29:23 -06:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
2018-04-08 01:44:42 -05:00
|
|
|
|
using SharedLibraryCore.Database;
|
2019-02-12 20:34:29 -06:00
|
|
|
|
using WebfrontCore.Middleware;
|
2018-02-21 19:29:23 -06:00
|
|
|
|
|
|
|
|
|
namespace WebfrontCore
|
|
|
|
|
{
|
|
|
|
|
public class Startup
|
|
|
|
|
{
|
2018-08-03 21:11:58 -05:00
|
|
|
|
private readonly IHostingEnvironment _appHost;
|
2018-04-08 01:44:42 -05:00
|
|
|
|
public static IConfigurationRoot Configuration { get; private set; }
|
|
|
|
|
|
2018-02-21 19:29:23 -06:00
|
|
|
|
public Startup(IHostingEnvironment env)
|
|
|
|
|
{
|
|
|
|
|
var builder = new ConfigurationBuilder()
|
|
|
|
|
.AddEnvironmentVariables();
|
2018-04-06 19:15:17 -05:00
|
|
|
|
|
2018-02-21 19:29:23 -06:00
|
|
|
|
Configuration = builder.Build();
|
2018-04-06 19:15:17 -05:00
|
|
|
|
|
2018-04-08 01:44:42 -05:00
|
|
|
|
_appHost = env;
|
2018-02-21 19:29:23 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
// Add framework services.
|
2019-02-16 17:18:50 -06:00
|
|
|
|
var mvcBuilder = services.AddMvc()
|
|
|
|
|
.ConfigureApplicationPartManager(_ =>
|
|
|
|
|
{
|
|
|
|
|
foreach (var assembly in Program.Manager.GetPluginAssemblies())
|
|
|
|
|
{
|
|
|
|
|
if (assembly.FullName.Contains("Views"))
|
|
|
|
|
{
|
|
|
|
|
_.ApplicationParts.Add(new CompiledRazorAssemblyPart(assembly));
|
|
|
|
|
}
|
2018-05-28 20:30:31 -05:00
|
|
|
|
|
2019-02-16 17:18:50 -06:00
|
|
|
|
else if (assembly.FullName.Contains("Web"))
|
|
|
|
|
{
|
|
|
|
|
_.ApplicationParts.Add(new AssemblyPart(assembly));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2018-05-28 20:30:31 -05:00
|
|
|
|
|
2019-02-16 17:18:50 -06:00
|
|
|
|
foreach (var asm in Program.Manager.GetPluginAssemblies())
|
2018-05-28 20:30:31 -05:00
|
|
|
|
{
|
2019-02-16 17:18:50 -06:00
|
|
|
|
mvcBuilder.AddApplicationPart(asm);
|
|
|
|
|
}
|
2018-05-28 20:30:31 -05:00
|
|
|
|
|
2018-04-08 01:44:42 -05:00
|
|
|
|
services.AddEntityFrameworkSqlite()
|
|
|
|
|
.AddDbContext<DatabaseContext>();
|
|
|
|
|
|
|
|
|
|
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
|
|
|
|
|
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options =>
|
|
|
|
|
{
|
|
|
|
|
options.AccessDeniedPath = "/";
|
|
|
|
|
options.LoginPath = "/";
|
|
|
|
|
});
|
2019-02-12 20:34:29 -06:00
|
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
services.AddLogging(_builder =>
|
|
|
|
|
{
|
|
|
|
|
_builder.AddDebug();
|
|
|
|
|
});
|
|
|
|
|
#endif
|
2018-02-21 19:29:23 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
|
|
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
|
|
|
|
{
|
|
|
|
|
if (env.IsDevelopment())
|
|
|
|
|
{
|
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
|
}
|
2019-01-26 20:33:37 -06:00
|
|
|
|
|
2018-02-21 19:29:23 -06:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
app.UseExceptionHandler("/Home/Error");
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-12 20:34:29 -06:00
|
|
|
|
if (Program.Manager.GetApplicationSettings().Configuration().EnableWebfrontConnectionWhitelist)
|
|
|
|
|
{
|
|
|
|
|
app.UseMiddleware<IPWhitelist>(Program.Manager.GetApplicationSettings().Configuration().WebfrontConnectionWhitelist);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-21 19:29:23 -06:00
|
|
|
|
app.UseStaticFiles();
|
2018-04-08 01:44:42 -05:00
|
|
|
|
app.UseAuthentication();
|
2018-04-04 14:38:34 -05:00
|
|
|
|
|
2018-02-21 19:29:23 -06:00
|
|
|
|
app.UseMvc(routes =>
|
|
|
|
|
{
|
|
|
|
|
routes.MapRoute(
|
|
|
|
|
name: "default",
|
|
|
|
|
template: "{controller=Home}/{action=Index}/{id?}");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|