|
1 | | -using Microsoft.AspNet.Builder; |
2 | | -using Microsoft.AspNet.Hosting; |
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.IO; |
| 4 | +using System.Linq; |
| 5 | +using System.Threading.Tasks; |
| 6 | +using Microsoft.AspNetCore.Builder; |
| 7 | +using Microsoft.AspNetCore.Hosting; |
| 8 | +using Microsoft.AspNetCore.Http; |
3 | 9 | using Microsoft.AspNet.SpaServices.Webpack; |
4 | | -using Microsoft.Extensions.Configuration; |
5 | 10 | using Microsoft.Extensions.DependencyInjection; |
6 | 11 | using Microsoft.Extensions.Logging; |
7 | | -using Microsoft.Extensions.PlatformAbstractions; |
| 12 | +using Newtonsoft.Json.Serialization; |
8 | 13 |
|
9 | | -namespace ReactExample |
| 14 | +namespace ReactGrid |
10 | 15 | { |
11 | 16 | public class Startup |
12 | 17 | { |
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. |
| 18 | + // This method gets called by the runtime. Use this method to add services to the container. |
26 | 19 | public void ConfigureServices(IServiceCollection services) |
27 | 20 | { |
28 | | - // Add MVC services to the services container. |
29 | | - services.AddMvc(); |
| 21 | + services.AddMvc().AddJsonOptions(options => |
| 22 | + { |
| 23 | + options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); |
| 24 | + }); |
30 | 25 | } |
31 | 26 |
|
32 | | - // Configure is called after ConfigureServices is called. |
33 | | - public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) |
| 27 | + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. |
| 28 | + public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IHostingEnvironment env) |
34 | 29 | { |
35 | | - loggerFactory.MinimumLevel = LogLevel.Warning; |
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(); |
| 30 | + app.UseDeveloperExceptionPage(); |
43 | 31 |
|
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 | | - // In dev mode, the JS/TS/etc is compiled and served dynamically and supports hot replacement. |
57 | | - // In production, we assume you've used webpack to emit the prebuilt content to disk. |
58 | 32 | if (env.IsDevelopment()) { |
59 | 33 | app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions { |
60 | 34 | HotModuleReplacement = true, |
61 | 35 | ReactHotModuleReplacement = true |
62 | 36 | }); |
63 | 37 | } |
64 | 38 |
|
65 | | - // Add static files to the request pipeline. |
66 | 39 | app.UseStaticFiles(); |
67 | | - |
68 | | - // Add MVC to the request pipeline. |
| 40 | + loggerFactory.AddConsole(); |
69 | 41 | app.UseMvc(routes => |
70 | 42 | { |
71 | | - routes.MapSpaFallbackRoute( |
| 43 | + routes.MapRoute( |
72 | 44 | name: "default", |
73 | | - defaults: new { controller="Home", action = "Index" }); |
| 45 | + template: "{controller=Home}/{action=Index}/{id?}"); |
| 46 | + |
| 47 | + routes.MapSpaFallbackRoute( |
| 48 | + name: "spa-fallback", |
| 49 | + defaults: new { controller = "Home", action = "Index" }); |
74 | 50 | }); |
75 | 51 | } |
| 52 | + |
| 53 | + public static void Main(string[] args) |
| 54 | + { |
| 55 | + var host = new WebHostBuilder() |
| 56 | + .UseContentRoot(Directory.GetCurrentDirectory()) |
| 57 | + .UseDefaultHostingConfiguration(args) |
| 58 | + .UseIISPlatformHandlerUrl() |
| 59 | + .UseKestrel() |
| 60 | + .UseStartup<Startup>() |
| 61 | + .Build(); |
| 62 | + |
| 63 | + host.Run(); |
| 64 | + } |
76 | 65 | } |
77 | 66 | } |
0 commit comments