|
| 1 | +using Microsoft.AspNet.Builder; |
| 2 | +using Microsoft.AspNet.Hosting; |
| 3 | +using Microsoft.AspNet.Routing.Template; |
| 4 | +using Microsoft.Dnx.Runtime; |
| 5 | +using Microsoft.Framework.Configuration; |
| 6 | +using Microsoft.Framework.DependencyInjection; |
| 7 | +using Microsoft.Framework.Logging; |
| 8 | + |
| 9 | +namespace ES2015Example |
| 10 | +{ |
| 11 | + public class Startup |
| 12 | + { |
| 13 | + public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv) |
| 14 | + { |
| 15 | + // Setup configuration sources. |
| 16 | + var builder = new ConfigurationBuilder() |
| 17 | + .SetBasePath(appEnv.ApplicationBasePath) |
| 18 | + .AddJsonFile("appsettings.json") |
| 19 | + .AddEnvironmentVariables(); |
| 20 | + Configuration = builder.Build(); |
| 21 | + } |
| 22 | + |
| 23 | + public IConfigurationRoot Configuration { get; set; } |
| 24 | + |
| 25 | + // This method gets called by the runtime. |
| 26 | + public void ConfigureServices(IServiceCollection services) |
| 27 | + { |
| 28 | + // Add MVC services to the services container. |
| 29 | + services.AddMvc(); |
| 30 | + } |
| 31 | + |
| 32 | + // Configure is called after ConfigureServices is called. |
| 33 | + public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) |
| 34 | + { |
| 35 | + loggerFactory.MinimumLevel = LogLevel.Information; |
| 36 | + loggerFactory.AddConsole(); |
| 37 | + loggerFactory.AddDebug(); |
| 38 | + |
| 39 | + // Configure the HTTP request pipeline. |
| 40 | + |
| 41 | + // Add the platform handler to the request pipeline. |
| 42 | + app.UseIISPlatformHandler(); |
| 43 | + |
| 44 | + // Add the following to the request pipeline only in development environment. |
| 45 | + if (env.IsDevelopment()) |
| 46 | + { |
| 47 | + app.UseDeveloperExceptionPage(); |
| 48 | + } |
| 49 | + else |
| 50 | + { |
| 51 | + // Add Error handling middleware which catches all application specific errors and |
| 52 | + // send the request to the following path or controller action. |
| 53 | + app.UseExceptionHandler("/Home/Error"); |
| 54 | + } |
| 55 | + |
| 56 | + app.UseMvc(routes => { |
| 57 | + routes.MapRoute( |
| 58 | + name: "Script", |
| 59 | + template: "{*filename}", |
| 60 | + defaults: new { controller="Script", action="Transpile" }, |
| 61 | + constraints: new { filename = @"js/(.*?)\.js" } |
| 62 | + ); |
| 63 | + }); |
| 64 | + |
| 65 | + // Add static files to the request pipeline. |
| 66 | + app.UseStaticFiles(); |
| 67 | + |
| 68 | + // Add MVC to the request pipeline. |
| 69 | + app.UseMvc(routes => |
| 70 | + { |
| 71 | + routes.MapRoute( |
| 72 | + name: "default", |
| 73 | + template: "{controller}/{action?}/{id?}", |
| 74 | + defaults: new { controller="Home", action = "Index" }); |
| 75 | + }); |
| 76 | + } |
| 77 | + } |
| 78 | +} |
0 commit comments