From b8875beefa555c9dbf631c19af4bce2fef0efa3d Mon Sep 17 00:00:00 2001 From: Kainoa Kanter Date: Thu, 27 Apr 2023 16:32:37 -0700 Subject: [PATCH] Revert "[Fix] Properly replace koa-fix-trailing-slashes with inhouse script (#9870)" This reverts commit 2cdaad588c82508734d04c2169503782dfe8556a. --- packages/backend/package.json | 1 + packages/backend/src/server/index.ts | 9 +++------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/backend/package.json b/packages/backend/package.json index 157f216b2..7b92b8311 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -79,6 +79,7 @@ "koa-json-body": "5.3.0", "koa-logger": "3.2.1", "koa-mount": "4.0.0", + "koa-remove-trailing-slashes": "2.0.3", "koa-send": "5.0.1", "koa-slow": "2.1.0", "koa-views": "7.0.2", diff --git a/packages/backend/src/server/index.ts b/packages/backend/src/server/index.ts index cd1425d6a..8035dcdd7 100644 --- a/packages/backend/src/server/index.ts +++ b/packages/backend/src/server/index.ts @@ -10,6 +10,7 @@ import Router from "@koa/router"; import mount from "koa-mount"; import koaLogger from "koa-logger"; import * as slow from "koa-slow"; + import { IsNull } from "typeorm"; import config from "@/config/index.js"; import Logger from "@/services/logger.js"; @@ -29,6 +30,7 @@ import proxyServer from "./proxy/index.js"; import webServer from "./web/index.js"; import { initializeStreamingServer } from "./api/streaming.js"; import { koaBody } from "koa-body"; +import removeTrailingSlash from "koa-remove-trailing-slashes"; import { v4 as uuid } from "uuid"; export const serverLogger = new Logger("server", "gray", false); @@ -37,12 +39,7 @@ export const serverLogger = new Logger("server", "gray", false); const app = new Koa(); app.proxy = true; -// Replace trailing slashes -app.use(async (ctx, next) => { - if (ctx.request.path !== "/" && ctx.request.path.endsWith("/")) - return ctx.redirect(ctx.request.path.replace(/\/$/, "")); - else await next(); -}); +app.use(removeTrailingSlash()); if (!["production", "test"].includes(process.env.NODE_ENV || "")) { // Logger