Skip to content

Commit 12b3369

Browse files
committed
Support OPTIONS requests in staticHandler.queryRoute
1 parent a929a00 commit 12b3369

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

.changeset/real-panthers-hear.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@remix-run/router": patch
3+
---
4+
5+
Support `OPTIONS` requests in `staticHandler.queryRoute`

packages/router/__tests__/router-test.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -12518,6 +12518,14 @@ describe("a router", () => {
1251812518
expect(data).toBe("PARENT LOADER");
1251912519
});
1252012520

12521+
it("should support OPTIONS requests", async () => {
12522+
let { queryRoute } = createStaticHandler(SSR_ROUTES);
12523+
let data = await queryRoute(
12524+
createRequest("/parent", { method: "OPTIONS" })
12525+
);
12526+
expect(data).toBe("PARENT LOADER");
12527+
});
12528+
1252112529
it("should support singular route load navigations (primitives)", async () => {
1252212530
let { queryRoute } = createStaticHandler(SSR_ROUTES);
1252312531
let data;
@@ -13276,15 +13284,15 @@ describe("a router", () => {
1327613284

1327713285
it("should handle unsupported methods with a 405 Response", async () => {
1327813286
try {
13279-
await queryRoute(createRequest("/", { method: "OPTIONS" }), {
13287+
await queryRoute(createRequest("/", { method: "TRACE" }), {
1328013288
routeId: "root",
1328113289
});
1328213290
expect(false).toBe(true);
1328313291
} catch (data) {
1328413292
expect(isRouteErrorResponse(data)).toBe(true);
1328513293
expect(data.status).toBe(405);
1328613294
expect(data.error).toEqual(
13287-
new Error('Invalid request method "OPTIONS"')
13295+
new Error('Invalid request method "TRACE"')
1328813296
);
1328913297
expect(data.internal).toBe(true);
1329013298
}

packages/router/router.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2421,7 +2421,7 @@ export function createStaticHandler(
24212421
let matches = matchRoutes(dataRoutes, location, basename);
24222422

24232423
// SSR supports HEAD requests while SPA doesn't
2424-
if (!isValidMethod(method) && method !== "head") {
2424+
if (!isValidMethod(method) && method !== "head" && method !== "options") {
24252425
throw getInternalRouterError(405, { method });
24262426
} else if (!matches) {
24272427
throw getInternalRouterError(404, { pathname: location.pathname });

0 commit comments

Comments
 (0)