[30a465f] | 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;
|
---|
[d2e69be] | 10 | using FarmatikoServices;
|
---|
| 11 | using FarmatikoData.FarmatikoRepoInterfaces;
|
---|
| 12 | using FarmatikoData.FarmatikoRepo;
|
---|
[30a465f] | 13 |
|
---|
| 14 | namespace Farmatiko
|
---|
| 15 | {
|
---|
| 16 | public class Startup
|
---|
| 17 | {
|
---|
| 18 | public Startup(IConfiguration configuration)
|
---|
| 19 | {
|
---|
| 20 | Configuration = configuration;
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | public IConfiguration Configuration { get; }
|
---|
| 24 |
|
---|
| 25 | // This method gets called by the runtime. Use this method to add services to the container.
|
---|
| 26 | public void ConfigureServices(IServiceCollection services)
|
---|
| 27 | {
|
---|
| 28 | services.AddControllersWithViews();
|
---|
| 29 | // In production, the Angular files will be served from this directory
|
---|
| 30 | services.AddSpaStaticFiles(configuration =>
|
---|
| 31 | {
|
---|
| 32 | configuration.RootPath = "ClientApp/dist";
|
---|
| 33 | });
|
---|
| 34 | var connectionString = Configuration.GetSection("ConnectionStrings").GetValue<string>("FarmatikoConnection");
|
---|
| 35 | services.AddEntityFrameworkNpgsql().AddDbContext<FarmatikoDataContext>(opt => opt.UseNpgsql(connectionString));
|
---|
| 36 |
|
---|
[d2e69be] | 37 | services.AddTransient<IHealthFacilityRepository, HealthFacilityRepository>();
|
---|
| 38 | services.AddTransient<IHealthFacilityService, HealthFacilityService>();
|
---|
[30a465f] | 39 | }
|
---|
| 40 |
|
---|
| 41 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
---|
| 42 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
---|
| 43 | {
|
---|
| 44 | if (env.IsDevelopment())
|
---|
| 45 | {
|
---|
| 46 | app.UseDeveloperExceptionPage();
|
---|
| 47 | }
|
---|
| 48 | else
|
---|
| 49 | {
|
---|
| 50 | app.UseExceptionHandler("/Error");
|
---|
| 51 | // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
---|
| 52 | app.UseHsts();
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | app.UseHttpsRedirection();
|
---|
| 56 | app.UseStaticFiles();
|
---|
| 57 | if (!env.IsDevelopment())
|
---|
| 58 | {
|
---|
| 59 | app.UseSpaStaticFiles();
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | app.UseRouting();
|
---|
| 63 |
|
---|
| 64 | app.UseEndpoints(endpoints =>
|
---|
| 65 | {
|
---|
| 66 | endpoints.MapControllerRoute(
|
---|
| 67 | name: "default",
|
---|
| 68 | pattern: "{controller}/{action=Index}/{id?}");
|
---|
| 69 | });
|
---|
| 70 |
|
---|
| 71 | app.UseSpa(spa =>
|
---|
| 72 | {
|
---|
| 73 | // To learn more about options for serving an Angular SPA from ASP.NET Core,
|
---|
| 74 | // see https://go.microsoft.com/fwlink/?linkid=864501
|
---|
| 75 |
|
---|
| 76 | spa.Options.SourcePath = "ClientApp";
|
---|
| 77 |
|
---|
| 78 | if (env.IsDevelopment())
|
---|
| 79 | {
|
---|
| 80 | spa.UseAngularCliServer(npmScript: "start");
|
---|
| 81 | }
|
---|
| 82 | });
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 | }
|
---|