Skip to content

Commit 7d1b11e

Browse files
committed
Update middlewares
1 parent 0c78730 commit 7d1b11e

File tree

3 files changed

+12
-26
lines changed

3 files changed

+12
-26
lines changed
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { redirect } from "react-router";
2-
import type { Route } from "../../+types/root";
1+
import { redirect, type unstable_MiddlewareFunction } from "react-router";
32

4-
export const ensureSecure: Route.unstable_MiddlewareFunction = async (
5-
{ request },
6-
next
7-
) => {
3+
export const ensureSecure: unstable_MiddlewareFunction = async ({
4+
request,
5+
}) => {
86
let proto = request.headers.get("x-forwarded-proto");
97
// this indirectly allows `http://localhost` because there is no
108
// "x-forwarded-proto" in the local server headers
@@ -13,7 +11,4 @@ export const ensureSecure: Route.unstable_MiddlewareFunction = async (
1311
secureUrl.protocol = "https:";
1412
throw redirect(secureUrl.toString());
1513
}
16-
// FIXME: Update RR to auto-bubble the internal response if `next` isn't
17-
// called so we can omit the return value
18-
return next();
1914
};
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
import { redirect } from "react-router";
2-
import type { Route } from "../../+types/root";
1+
import { redirect, type unstable_MiddlewareFunction } from "react-router";
32

4-
export const removeTrailingSlashes: Route.unstable_MiddlewareFunction = async (
5-
{ request },
6-
next
7-
) => {
3+
export const removeTrailingSlashes: unstable_MiddlewareFunction = async ({
4+
request,
5+
}) => {
86
let url = new URL(request.url);
97
if (url.pathname.endsWith("/") && url.pathname !== "/") {
108
url.pathname = url.pathname.slice(0, -1);
119
throw redirect(url.toString());
1210
}
13-
// FIXME: Update RR to auto-bubble the internal response if `next` isn't
14-
// called so we can omit the return value
15-
return next();
1611
};

app/modules/redirects/.server/index.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Route } from "../../../+types/root";
1+
import { type unstable_MiddlewareFunction } from "react-router";
22
import { checkUrl } from "./check-url";
33
import { getRedirects } from "./get-redirects";
44

@@ -15,15 +15,11 @@ import { getRedirects } from "./get-redirects";
1515
*
1616
* @param request Web Fetch Request to possibly redirect
1717
*/
18-
export const handleRedirects: Route.unstable_MiddlewareFunction = async (
19-
{ request },
20-
next
21-
) => {
18+
export const handleRedirects: unstable_MiddlewareFunction = async ({
19+
request,
20+
}) => {
2221
let redirects = await getRedirects();
2322
let url = new URL(request.url);
2423
let response = await checkUrl(url.pathname, redirects);
2524
if (response) throw response;
26-
// FIXME: Update RR to auto-bubble the internal response if `next` isn't
27-
// called so we can omit the return value
28-
return next();
2925
};

0 commit comments

Comments
 (0)