From 05ccb4d8f1bbe3fb64e117136b4a89bcfb0b0b33 Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 27 Oct 2020 19:21:35 +0800 Subject: Split front and back end. --- Timeline/Routes/UnknownEndpointMiddleware.cs | 39 ---------------------------- 1 file changed, 39 deletions(-) delete mode 100644 Timeline/Routes/UnknownEndpointMiddleware.cs (limited to 'Timeline/Routes/UnknownEndpointMiddleware.cs') diff --git a/Timeline/Routes/UnknownEndpointMiddleware.cs b/Timeline/Routes/UnknownEndpointMiddleware.cs deleted file mode 100644 index 25ec563c..00000000 --- a/Timeline/Routes/UnknownEndpointMiddleware.cs +++ /dev/null @@ -1,39 +0,0 @@ -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Http; -using System; -using System.Net.Mime; -using System.Text.Json; -using Timeline.Models.Http; - -namespace Timeline.Routes -{ - public static class UnknownEndpointMiddleware - { - public static void Attach(IApplicationBuilder app) - { - app.Use(async (context, next) => - { - if (context.GetEndpoint() != null) - { - await next(); - return; - } - - if (context.Request.Path.StartsWithSegments("/api", StringComparison.OrdinalIgnoreCase)) - { - context.Response.StatusCode = StatusCodes.Status400BadRequest; - context.Response.ContentType = MediaTypeNames.Application.Json; - - var body = JsonSerializer.SerializeToUtf8Bytes(ErrorResponse.Common.UnknownEndpoint(), new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }); - - context.Response.ContentLength = body.Length; - await context.Response.Body.WriteAsync(body); - await context.Response.CompleteAsync(); - return; - } - - await next(); - }); - } - } -} -- cgit v1.2.3