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