Skip to content

Commit

Permalink
Support OPTIONS requests in staticHandler.queryRoute
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 committed Jan 17, 2023
1 parent a929a00 commit 12b3369
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/real-panthers-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/router": patch
---

Support `OPTIONS` requests in `staticHandler.queryRoute`
12 changes: 10 additions & 2 deletions packages/router/__tests__/router-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12518,6 +12518,14 @@ describe("a router", () => {
expect(data).toBe("PARENT LOADER");
});

it("should support OPTIONS requests", async () => {
let { queryRoute } = createStaticHandler(SSR_ROUTES);
let data = await queryRoute(
createRequest("/parent", { method: "OPTIONS" })
);
expect(data).toBe("PARENT LOADER");
});

it("should support singular route load navigations (primitives)", async () => {
let { queryRoute } = createStaticHandler(SSR_ROUTES);
let data;
Expand Down Expand Up @@ -13276,15 +13284,15 @@ describe("a router", () => {

it("should handle unsupported methods with a 405 Response", async () => {
try {
await queryRoute(createRequest("/", { method: "OPTIONS" }), {
await queryRoute(createRequest("/", { method: "TRACE" }), {
routeId: "root",
});
expect(false).toBe(true);
} catch (data) {
expect(isRouteErrorResponse(data)).toBe(true);
expect(data.status).toBe(405);
expect(data.error).toEqual(
new Error('Invalid request method "OPTIONS"')
new Error('Invalid request method "TRACE"')
);
expect(data.internal).toBe(true);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2421,7 +2421,7 @@ export function createStaticHandler(
let matches = matchRoutes(dataRoutes, location, basename);

// SSR supports HEAD requests while SPA doesn't
if (!isValidMethod(method) && method !== "head") {
if (!isValidMethod(method) && method !== "head" && method !== "options") {
throw getInternalRouterError(405, { method });
} else if (!matches) {
throw getInternalRouterError(404, { pathname: location.pathname });
Expand Down

0 comments on commit 12b3369

Please sign in to comment.