source: Farmatiko/Startup.cs@ 30a465f

Last change on this file since 30a465f was 30a465f, checked in by DimitarSlezenkovski <dslezenkovski@…>, 2 years ago

Initial commit

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