Skip to content

Commit

Permalink
fix(swagger): fix redirectMiddleware to be a middleware instead of a …
Browse files Browse the repository at this point in the history
….get()
  • Loading branch information
Romakita committed Feb 29, 2024
1 parent 37cdc0c commit a1f98e8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/specs/swagger/src/SwaggerModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class SwaggerModule implements OnRoutesInit, OnReady {
this.settings.forEach((conf: SwaggerSettings) => {
const {path = "/"} = conf;

this.app.get(path, useContextHandler(redirectMiddleware(path)));
this.app.use(path, useContextHandler(redirectMiddleware(path)));
this.app.use(path, this.createRouter(conf, urls));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {PlatformContext} from "@tsed/common";
*/
export function redirectMiddleware(path: string) {
return (ctx: PlatformContext) => {
if (ctx.request.url === path && !ctx.request.url.match(/\/$/)) {
if (ctx.request.method === "GET" && ctx.request.url === path && !ctx.request.url.match(/\/$/)) {
ctx.response.redirect(302, `${path}/`);
}
};
Expand Down

0 comments on commit a1f98e8

Please sign in to comment.