Remove dependency on routing in sample

Removing the routing dependency since this is moving lower in the stack.
This commit is contained in:
Ryan Nowak 2016-02-02 09:03:53 -08:00
parent 492c0798b1
commit 96063e2476
2 changed files with 17 additions and 23 deletions

View File

@ -7,7 +7,6 @@ using Microsoft.AspNetCore.Antiforgery;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Newtonsoft.Json; using Newtonsoft.Json;
@ -18,8 +17,6 @@ namespace AntiforgerySample
{ {
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.AddRouting();
// Angular's default header name for sending the XSRF token. // Angular's default header name for sending the XSRF token.
services.AddAntiforgery(options => options.HeaderName = "X-XSRF-TOKEN"); services.AddAntiforgery(options => options.HeaderName = "X-XSRF-TOKEN");
@ -45,15 +42,14 @@ namespace AntiforgerySample
app.UseDefaultFiles(); app.UseDefaultFiles();
app.UseStaticFiles(); app.UseStaticFiles();
var routes = new RouteBuilder(app); app.Map("/api/items", a => a.Run(async context =>
{
routes.MapGet("api/items", (HttpContext context) => if (string.Equals("GET", context.Request.Method, StringComparison.OrdinalIgnoreCase))
{ {
var items = repository.GetItems(); var items = repository.GetItems();
return context.Response.WriteAsync(JsonConvert.SerializeObject(items)); await context.Response.WriteAsync(JsonConvert.SerializeObject(items));
}); }
else if (string.Equals("POST", context.Request.Method, StringComparison.OrdinalIgnoreCase))
routes.MapPost("api/items", async (HttpContext context) =>
{ {
// This will throw if the token is invalid. // This will throw if the token is invalid.
await antiforgery.ValidateRequestAsync(context); await antiforgery.ValidateRequestAsync(context);
@ -66,9 +62,8 @@ namespace AntiforgerySample
} }
context.Response.StatusCode = 204; context.Response.StatusCode = 204;
}); }
}));
app.UseRouter(routes.Build());
} }
public static void Main(string[] args) public static void Main(string[] args)

View File

@ -6,7 +6,6 @@
"Microsoft.AspNetCore.Http.Abstractions": "1.0.0-*", "Microsoft.AspNetCore.Http.Abstractions": "1.0.0-*",
"Microsoft.AspNetCore.Http.Extensions": "1.0.0-*", "Microsoft.AspNetCore.Http.Extensions": "1.0.0-*",
"Microsoft.AspNetCore.IISPlatformHandler": "1.0.0-*", "Microsoft.AspNetCore.IISPlatformHandler": "1.0.0-*",
"Microsoft.AspNetCore.Routing.Extensions": "1.0.0-*",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*",
"Microsoft.AspNetCore.StaticFiles": "1.0.0-*", "Microsoft.AspNetCore.StaticFiles": "1.0.0-*",
"Microsoft.NETCore.Platforms": "1.0.1-*", "Microsoft.NETCore.Platforms": "1.0.1-*",