[30a465f] | 1 | using Microsoft.AspNetCore.Builder;
|
---|
| 2 | using Microsoft.AspNetCore.Hosting;
|
---|
| 3 | using Microsoft.AspNetCore.SpaServices.AngularCli;
|
---|
| 4 | using Microsoft.Extensions.Configuration;
|
---|
| 5 | using Microsoft.Extensions.DependencyInjection;
|
---|
| 6 | using Microsoft.Extensions.Hosting;
|
---|
| 7 | using FarmatikoData;
|
---|
| 8 | using Microsoft.EntityFrameworkCore;
|
---|
[d2e69be] | 9 | using FarmatikoServices;
|
---|
| 10 | using FarmatikoData.FarmatikoRepoInterfaces;
|
---|
| 11 | using FarmatikoData.FarmatikoRepo;
|
---|
[e42f61a] | 12 | using FarmatikoServices.FarmatikoServiceInterfaces;
|
---|
| 13 | using FarmatikoServices.Services;
|
---|
[c406ae5] | 14 | using Microsoft.Extensions.Logging;
|
---|
[30a465f] | 15 |
|
---|
| 16 | namespace Farmatiko
|
---|
| 17 | {
|
---|
| 18 | public class Startup
|
---|
| 19 | {
|
---|
[e42f61a] | 20 | readonly string MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
|
---|
| 21 |
|
---|
[30a465f] | 22 | public Startup(IConfiguration configuration)
|
---|
| 23 | {
|
---|
| 24 | Configuration = configuration;
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | public IConfiguration Configuration { get; }
|
---|
| 28 |
|
---|
| 29 | // This method gets called by the runtime. Use this method to add services to the container.
|
---|
| 30 | public void ConfigureServices(IServiceCollection services)
|
---|
| 31 | {
|
---|
[e42f61a] | 32 | services.AddCors(options =>
|
---|
| 33 | {
|
---|
| 34 | options.AddPolicy(name: MyAllowSpecificOrigins,
|
---|
| 35 | builder =>
|
---|
| 36 | {
|
---|
| 37 | builder.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin();
|
---|
| 38 | });
|
---|
| 39 | });
|
---|
| 40 |
|
---|
[30a465f] | 41 | services.AddControllersWithViews();
|
---|
| 42 | // In production, the Angular files will be served from this directory
|
---|
| 43 | services.AddSpaStaticFiles(configuration =>
|
---|
| 44 | {
|
---|
| 45 | configuration.RootPath = "ClientApp/dist";
|
---|
| 46 | });
|
---|
| 47 | var connectionString = Configuration.GetSection("ConnectionStrings").GetValue<string>("FarmatikoConnection");
|
---|
| 48 | services.AddEntityFrameworkNpgsql().AddDbContext<FarmatikoDataContext>(opt => opt.UseNpgsql(connectionString));
|
---|
| 49 |
|
---|
[6f203af] | 50 | services.AddTransient<IPHRepo, PHRepo>();
|
---|
| 51 | services.AddTransient<IRepository, Repository>();
|
---|
| 52 | services.AddTransient<IAdminRepo, AdminRepo>();
|
---|
[4e72684] | 53 |
|
---|
[6f203af] | 54 | services.AddTransient<IPHService, PHService>();
|
---|
| 55 | services.AddTransient<IAdminService, AdminService>();
|
---|
| 56 | services.AddTransient<IService, Service>();
|
---|
[a55ef91] | 57 |
|
---|
| 58 | services.AddTransient<IProcessJSONService, ProcessJSONService>();
|
---|
[c406ae5] | 59 |
|
---|
| 60 | services.AddTransient<ILogger, Logger<ProcessJSONService>>();
|
---|
[30a465f] | 61 | }
|
---|
| 62 |
|
---|
| 63 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
---|
| 64 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
---|
| 65 | {
|
---|
| 66 | if (env.IsDevelopment())
|
---|
| 67 | {
|
---|
| 68 | app.UseDeveloperExceptionPage();
|
---|
| 69 | }
|
---|
| 70 | else
|
---|
| 71 | {
|
---|
| 72 | app.UseExceptionHandler("/Error");
|
---|
| 73 | // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
---|
| 74 | app.UseHsts();
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | app.UseHttpsRedirection();
|
---|
| 78 | app.UseStaticFiles();
|
---|
| 79 | if (!env.IsDevelopment())
|
---|
| 80 | {
|
---|
| 81 | app.UseSpaStaticFiles();
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | app.UseRouting();
|
---|
| 85 |
|
---|
[e42f61a] | 86 | app.UseCors(MyAllowSpecificOrigins);
|
---|
| 87 |
|
---|
[30a465f] | 88 | app.UseEndpoints(endpoints =>
|
---|
| 89 | {
|
---|
| 90 | endpoints.MapControllerRoute(
|
---|
| 91 | name: "default",
|
---|
| 92 | pattern: "{controller}/{action=Index}/{id?}");
|
---|
| 93 | });
|
---|
| 94 |
|
---|
| 95 | app.UseSpa(spa =>
|
---|
| 96 | {
|
---|
| 97 | // To learn more about options for serving an Angular SPA from ASP.NET Core,
|
---|
| 98 | // see https://go.microsoft.com/fwlink/?linkid=864501
|
---|
| 99 |
|
---|
| 100 | spa.Options.SourcePath = "ClientApp";
|
---|
| 101 |
|
---|
| 102 | if (env.IsDevelopment())
|
---|
| 103 | {
|
---|
| 104 | spa.UseAngularCliServer(npmScript: "start");
|
---|
| 105 | }
|
---|
| 106 | });
|
---|
| 107 | }
|
---|
| 108 | }
|
---|
| 109 | }
|
---|