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