1 | using Microsoft.AspNetCore.Builder;
|
---|
2 | using Microsoft.AspNetCore.Hosting;
|
---|
3 | using Microsoft.AspNetCore.HttpsPolicy;
|
---|
4 | using Microsoft.AspNetCore.SpaServices.AngularCli;
|
---|
5 | using Microsoft.Extensions.Configuration;
|
---|
6 | using Microsoft.Extensions.DependencyInjection;
|
---|
7 | using Microsoft.Extensions.Hosting;
|
---|
8 | using FarmatikoData;
|
---|
9 | using Microsoft.EntityFrameworkCore;
|
---|
10 | using FarmatikoServices;
|
---|
11 | using FarmatikoData.FarmatikoRepoInterfaces;
|
---|
12 | using FarmatikoData.FarmatikoRepo;
|
---|
13 | using FarmatikoServices.FarmatikoServiceInterfaces;
|
---|
14 | using FarmatikoServices.Services;
|
---|
15 |
|
---|
16 | namespace Farmatiko
|
---|
17 | {
|
---|
18 | public class Startup
|
---|
19 | {
|
---|
20 | readonly string MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
|
---|
21 |
|
---|
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 | {
|
---|
32 | services.AddCors(options =>
|
---|
33 | {
|
---|
34 | options.AddPolicy(name: MyAllowSpecificOrigins,
|
---|
35 | builder =>
|
---|
36 | {
|
---|
37 | builder.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin();
|
---|
38 | });
|
---|
39 | });
|
---|
40 |
|
---|
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 |
|
---|
50 | services.AddTransient<IHealthFacilityRepository, HealthFacilityRepository>();
|
---|
51 | services.AddTransient<IHealthFacilityService, HealthFacilityService>();
|
---|
52 | services.AddTransient<IHealthcareWorkerRepository, HealthcareWorkerRepository>();
|
---|
53 | services.AddTransient<IHealthcareWorkerService, HealthcareWorkerService>();
|
---|
54 | }
|
---|
55 |
|
---|
56 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
---|
57 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
---|
58 | {
|
---|
59 | if (env.IsDevelopment())
|
---|
60 | {
|
---|
61 | app.UseDeveloperExceptionPage();
|
---|
62 | }
|
---|
63 | else
|
---|
64 | {
|
---|
65 | app.UseExceptionHandler("/Error");
|
---|
66 | // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
---|
67 | app.UseHsts();
|
---|
68 | }
|
---|
69 |
|
---|
70 | app.UseHttpsRedirection();
|
---|
71 | app.UseStaticFiles();
|
---|
72 | if (!env.IsDevelopment())
|
---|
73 | {
|
---|
74 | app.UseSpaStaticFiles();
|
---|
75 | }
|
---|
76 |
|
---|
77 | app.UseRouting();
|
---|
78 |
|
---|
79 | app.UseCors(MyAllowSpecificOrigins);
|
---|
80 |
|
---|
81 | app.UseEndpoints(endpoints =>
|
---|
82 | {
|
---|
83 | endpoints.MapControllerRoute(
|
---|
84 | name: "default",
|
---|
85 | pattern: "{controller}/{action=Index}/{id?}");
|
---|
86 | });
|
---|
87 |
|
---|
88 | app.UseSpa(spa =>
|
---|
89 | {
|
---|
90 | // To learn more about options for serving an Angular SPA from ASP.NET Core,
|
---|
91 | // see https://go.microsoft.com/fwlink/?linkid=864501
|
---|
92 |
|
---|
93 | spa.Options.SourcePath = "ClientApp";
|
---|
94 |
|
---|
95 | if (env.IsDevelopment())
|
---|
96 | {
|
---|
97 | spa.UseAngularCliServer(npmScript: "start");
|
---|
98 | }
|
---|
99 | });
|
---|
100 | }
|
---|
101 | }
|
---|
102 | }
|
---|