Advertisement
Guest User

Startup.cs

a guest
Sep 16th, 2018
766
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.12 KB | None | 0 0
  1. using Microsoft.AspNetCore.Builder;
  2. using Microsoft.AspNetCore.Hosting;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Microsoft.AspNetCore.SpaServices.AngularCli;
  5. using Microsoft.Extensions.Configuration;
  6. using Microsoft.Extensions.DependencyInjection;
  7.  
  8. namespace WrongApiUrlTestApp
  9. {
  10.     public class Startup
  11.     {
  12.         public Startup(IConfiguration configuration)
  13.         {
  14.             Configuration = configuration;
  15.         }
  16.  
  17.         public IConfiguration Configuration { get; }
  18.  
  19.         // This method gets called by the runtime. Use this method to add services to the container.
  20.         public void ConfigureServices(IServiceCollection services)
  21.         {
  22.             services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
  23.  
  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, IHostingEnvironment env)
  33.         {
  34.             if (env.IsDevelopment())
  35.             {
  36.                 app.UseDeveloperExceptionPage();
  37.             }
  38.             else
  39.             {
  40.                 app.UseExceptionHandler("/Error");
  41.             }
  42.  
  43.             app.UseStaticFiles();
  44.             app.UseSpaStaticFiles();
  45.  
  46.             app.UseMvc(routes =>
  47.             {
  48.                 routes.MapRoute(
  49.                     name: "default",
  50.                     template: "{controller}/{action=Index}/{id?}");
  51.             });
  52.  
  53.             app.UseSpa(spa =>
  54.             {
  55.                 // To learn more about options for serving an Angular SPA from ASP.NET Core,
  56.                 // see https://go.microsoft.com/fwlink/?linkid=864501
  57.  
  58.                 spa.Options.SourcePath = "ClientApp";
  59.  
  60.                 if (env.IsDevelopment())
  61.                 {
  62.                     spa.UseAngularCliServer(npmScript: "start");
  63.                 }
  64.             });
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement