From 1f7ec8e4bf4d37361061a6b83dc5df74a1587003 Mon Sep 17 00:00:00 2001 From: SteveSandersonMS Date: Fri, 8 Apr 2016 12:18:24 +0100 Subject: [PATCH] Update ReactGrid example to RC2 --- .../ReactGrid/Controllers/HomeController.cs | 2 +- .../Controllers/PeopleApiController.cs | 6 +- samples/react/ReactGrid/Startup.cs | 87 ++++++++----------- .../react/ReactGrid/Views/_ViewImports.cshtml | 2 +- samples/react/ReactGrid/package.json | 3 + samples/react/ReactGrid/project.json | 46 ++++++---- 6 files changed, 74 insertions(+), 72 deletions(-) diff --git a/samples/react/ReactGrid/Controllers/HomeController.cs b/samples/react/ReactGrid/Controllers/HomeController.cs index 76bb4c7..b7a48c4 100755 --- a/samples/react/ReactGrid/Controllers/HomeController.cs +++ b/samples/react/ReactGrid/Controllers/HomeController.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNet.Mvc; +using Microsoft.AspNetCore.Mvc; namespace ReactExample.Controllers { diff --git a/samples/react/ReactGrid/Controllers/PeopleApiController.cs b/samples/react/ReactGrid/Controllers/PeopleApiController.cs index 4cba391..fd3e29c 100644 --- a/samples/react/ReactGrid/Controllers/PeopleApiController.cs +++ b/samples/react/ReactGrid/Controllers/PeopleApiController.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations; using System.Threading.Tasks; -using Microsoft.AspNet.Mvc; +using Microsoft.AspNetCore.Mvc; namespace ReactExample.Controllers { @@ -10,9 +10,9 @@ namespace ReactExample.Controllers public ActionResult UpdatePerson([FromBody] PersonDto person) { if (!ModelState.IsValid) { - return HttpBadRequest(ModelState); + return BadRequest(ModelState); } else { - return new HttpOkResult(); + return new OkResult(); } } } diff --git a/samples/react/ReactGrid/Startup.cs b/samples/react/ReactGrid/Startup.cs index caa0d48..33149ca 100755 --- a/samples/react/ReactGrid/Startup.cs +++ b/samples/react/ReactGrid/Startup.cs @@ -1,60 +1,34 @@ -using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Hosting; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; using Microsoft.AspNet.SpaServices.Webpack; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.PlatformAbstractions; +using Newtonsoft.Json.Serialization; -namespace ReactExample +namespace ReactGrid { public class Startup { - public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv) - { - // Setup configuration sources. - var builder = new ConfigurationBuilder() - .SetBasePath(appEnv.ApplicationBasePath) - .AddJsonFile("appsettings.json") - .AddEnvironmentVariables(); - Configuration = builder.Build(); - } - - public IConfigurationRoot Configuration { get; set; } - - // This method gets called by the runtime. + // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - // Add MVC services to the services container. - services.AddMvc(); + services.AddMvc().AddJsonOptions(options => + { + options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); + }); } - // Configure is called after ConfigureServices is called. - public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IHostingEnvironment env) { - loggerFactory.MinimumLevel = LogLevel.Warning; - loggerFactory.AddConsole(); - loggerFactory.AddDebug(); + app.UseDeveloperExceptionPage(); - // Configure the HTTP request pipeline. - - // Add the platform handler to the request pipeline. - app.UseIISPlatformHandler(); - - // Add the following to the request pipeline only in development environment. - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - } - else - { - // Add Error handling middleware which catches all application specific errors and - // send the request to the following path or controller action. - app.UseExceptionHandler("/Home/Error"); - } - - // In dev mode, the JS/TS/etc is compiled and served dynamically and supports hot replacement. - // In production, we assume you've used webpack to emit the prebuilt content to disk. if (env.IsDevelopment()) { app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions { HotModuleReplacement = true, @@ -62,16 +36,31 @@ namespace ReactExample }); } - // Add static files to the request pipeline. app.UseStaticFiles(); - - // Add MVC to the request pipeline. + loggerFactory.AddConsole(); app.UseMvc(routes => { - routes.MapSpaFallbackRoute( + routes.MapRoute( name: "default", - defaults: new { controller="Home", action = "Index" }); + template: "{controller=Home}/{action=Index}/{id?}"); + + routes.MapSpaFallbackRoute( + name: "spa-fallback", + defaults: new { controller = "Home", action = "Index" }); }); } + + public static void Main(string[] args) + { + var host = new WebHostBuilder() + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseDefaultHostingConfiguration(args) + .UseIISPlatformHandlerUrl() + .UseKestrel() + .UseStartup() + .Build(); + + host.Run(); + } } } diff --git a/samples/react/ReactGrid/Views/_ViewImports.cshtml b/samples/react/ReactGrid/Views/_ViewImports.cshtml index 9a3224d..5b5b5c3 100755 --- a/samples/react/ReactGrid/Views/_ViewImports.cshtml +++ b/samples/react/ReactGrid/Views/_ViewImports.cshtml @@ -1,3 +1,3 @@ @using ReactExample -@addTagHelper "*, Microsoft.AspNet.Mvc.TagHelpers" +@addTagHelper "*, Microsoft.AspNetCore.Mvc.TagHelpers" @addTagHelper "*, Microsoft.AspNet.SpaServices" diff --git a/samples/react/ReactGrid/package.json b/samples/react/ReactGrid/package.json index 301f288..a2de71c 100644 --- a/samples/react/ReactGrid/package.json +++ b/samples/react/ReactGrid/package.json @@ -18,6 +18,9 @@ "webpack-externals-plugin": "^1.0.0" }, "devDependencies": { + "aspnet-prerendering": "^1.0.0", + "aspnet-webpack": "^1.0.3", + "aspnet-webpack-react": "^1.0.1", "babel-loader": "^6.2.1", "babel-plugin-react-transform": "^2.0.0", "babel-preset-es2015": "^6.3.13", diff --git a/samples/react/ReactGrid/project.json b/samples/react/ReactGrid/project.json index de2377b..5f9823a 100755 --- a/samples/react/ReactGrid/project.json +++ b/samples/react/ReactGrid/project.json @@ -1,19 +1,21 @@ { - "webroot": "wwwroot", "version": "1.0.0-*", - "tooling": { - "defaultNamespace": "ReactExample" + "compilationOptions": { + "emitEntryPoint": true, + "warningsAsErrors": true, + "preserveCompilationContext": true }, "dependencies": { - "Microsoft.AspNet.Diagnostics": "1.0.0-rc1-*", - "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-*", - "Microsoft.AspNet.Mvc": "6.0.0-rc1-*", - "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-*", - "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-*", - "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-*", - "Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-*", - "Microsoft.Extensions.Logging.Console": "1.0.0-rc1-*", - "Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-*", + "Microsoft.AspNetCore.Diagnostics": "1.0.0-*", + "Microsoft.AspNetCore.IISPlatformHandler": "1.0.0-*", + "Microsoft.AspNetCore.Mvc": "1.0.0-*", + "Microsoft.AspNetCore.Mvc.TagHelpers": "1.0.0-*", + "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", + "Microsoft.AspNetCore.StaticFiles": "1.0.0-*", + "Microsoft.Extensions.Configuration.Json": "1.0.0-*", + "Microsoft.Extensions.Logging.Console": "1.0.0-*", + "Microsoft.NETCore.Platforms": "1.0.1-*", + "Microsoft.Extensions.Logging.Debug": "1.0.0-*", "Microsoft.AspNet.ReactServices": "1.0.0-*" }, "commands": { @@ -21,23 +23,31 @@ }, "frameworks": { "dnx451": {}, - "dnxcore50": {} + "netstandardapp1.5": { + "imports": [ + "dnxcore50", + "portable-net451+win8" + ], + "dependencies": { + "NETStandard.Library": "1.5.0-*" + } + } }, + "exclude": [ "wwwroot", - "node_modules", - "bower_components" + "node_modules" ], "publishExclude": [ "node_modules", - "bower_components", "**.xproj", "**.user", "**.vspscc" ], "scripts": { - "prepublish": [ - "npm install" + "prepare": [ + "npm install", + "webpack" ] } }