Skip to content

Commit

Permalink
fix(next): Avoid appending ? if querystring is empty (#71)
Browse files Browse the repository at this point in the history
Co-authored-by: David Mytton <[email protected]>
  • Loading branch information
blaine-arcjet and davidmytton authored Dec 15, 2023
1 parent 46fd6b3 commit 16ca958
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 5 additions & 2 deletions arcjet-next/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,12 @@ export default function arcjetNext<const Rules extends (Primitive | Product)[]>(
const method = request.method ?? "";
const host = headers.get("host") ?? "";
let path;
// TODO(#224): nextUrl has formatting logic when you `toString` but we don't account for that here
// TODO(#36): nextUrl has formatting logic when you `toString` but we don't account for that here
if (typeof request.nextUrl !== "undefined") {
path = request.nextUrl.pathname + "?" + request.nextUrl.search;
path = request.nextUrl.pathname;
if (request.nextUrl.search !== "") {
path += "?" + request.nextUrl.search;
}
} else {
path = request.url ?? "";
}
Expand Down
10 changes: 10 additions & 0 deletions examples/nextjs-14-app-dir-rl/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { createMiddleware, rateLimit } from "@arcjet/next";
export const config = {
// matcher tells Next.js which routes to run the middleware on
matcher: ["/"],
};
const middleware = createMiddleware({
key: "ajkey_yourkey",
rules: [],
});
export default middleware;

0 comments on commit 16ca958

Please sign in to comment.