diff --git a/app/routes/attack.test/route.tsx b/app/routes/attack.test/route.tsx index 99ca3a0..3b57ff7 100644 --- a/app/routes/attack.test/route.tsx +++ b/app/routes/attack.test/route.tsx @@ -1,5 +1,4 @@ import type { LoaderFunctionArgs } from "@remix-run/node"; -import { json } from "@remix-run/node"; import arcjet from "~/arcjet"; export async function loader(args: LoaderFunctionArgs) { @@ -12,12 +11,12 @@ export async function loader(args: LoaderFunctionArgs) { console.log("Arcjet decision: ", decision); if (decision.isDenied() && decision.reason.isShield()) { - return json({ message: "Forbidden" }, { status: 403 }); + return Response.json({ message: "Forbidden" }, { status: 403 }); } else if (decision.isErrored()) { console.error("Arcjet error:", decision.reason); if (decision.reason.message == "[unauthenticated] invalid key") { - return json( + return Response.json( { message: "Invalid Arcjet key. Is the ARCJET_KEY environment variable set?", @@ -25,12 +24,12 @@ export async function loader(args: LoaderFunctionArgs) { { status: 500 }, ); } else { - return json( + return Response.json( { message: "Internal server error: " + decision.reason.message }, { status: 500 }, ); } } - return json({ message: "Hello, world!" }, { status: 200 }); + return Response.json({ message: "Hello, world!" }, { status: 200 }); } diff --git a/app/routes/bots.test/route.tsx b/app/routes/bots.test/route.tsx index f192b2b..14e27c4 100644 --- a/app/routes/bots.test/route.tsx +++ b/app/routes/bots.test/route.tsx @@ -1,6 +1,5 @@ import { detectBot, fixedWindow } from "@arcjet/remix"; import type { LoaderFunctionArgs } from "@remix-run/node"; -import { json } from "@remix-run/node"; import arcjet from "~/arcjet"; // Add rules to the base Arcjet instance outside of the handler function @@ -30,23 +29,23 @@ export async function loader(args: LoaderFunctionArgs) { // Use the IP analysis to customize the response based on the country if (decision.ip.hasCountry() && decision.ip.country == "JP") { - return json({ message: "Konnichiwa!" }, { status: 200 }); + return Response.json({ message: "Konnichiwa!" }, { status: 200 }); } // Always deny requests from VPNs if (decision.ip.isVpn()) { - return json({ message: "VPNs are forbidden" }, { status: 403 }); + return Response.json({ message: "VPNs are forbidden" }, { status: 403 }); } if (decision.isDenied() && decision.reason.isBot()) { - return json({ message: "Bots are forbidden" }, { status: 403 }); + return Response.json({ message: "Bots are forbidden" }, { status: 403 }); } else if (decision.isDenied() && decision.reason.isRateLimit()) { - return json({ message: "Too many requests" }, { status: 429 }); + return Response.json({ message: "Too many requests" }, { status: 429 }); } else if (decision.isErrored()) { console.error("Arcjet error:", decision.reason); if (decision.reason.message == "[unauthenticated] invalid key") { - return json( + return Response.json( { message: "Invalid Arcjet key. Is the ARCJET_KEY environment variable set?", @@ -54,12 +53,12 @@ export async function loader(args: LoaderFunctionArgs) { { status: 500 }, ); } else { - return json( + return Response.json( { message: "Internal server error: " + decision.reason.message }, { status: 500 }, ); } } - return json({ message: "Hello, world!" }, { status: 200 }); + return Response.json({ message: "Hello, world!" }, { status: 200 }); } diff --git a/app/routes/rate-limit.tsx b/app/routes/rate-limit.tsx index 25cbe66..e150b26 100644 --- a/app/routes/rate-limit.tsx +++ b/app/routes/rate-limit.tsx @@ -5,7 +5,6 @@ import type { LoaderFunctionArgs, MetaFunction, } from "@remix-run/node"; -import { json } from "@remix-run/node"; import { Form, Link, @@ -104,7 +103,7 @@ export async function action(args: ActionFunctionArgs) { const reset = decision.reason.resetTime; if (reset === undefined) { - return json( + return Response.json( { message: "too many requests. Please try again later." }, { status: 429, headers }, ); @@ -115,14 +114,14 @@ export async function action(args: ActionFunctionArgs) { const minutes = Math.ceil(seconds / 60); if (minutes > 1) { - return json( + return Response.json( { message: `too many requests. Please try again in ${minutes} minutes.`, }, { status: 429, headers }, ); } else { - return json( + return Response.json( { message: `too many requests. Please try again in ${seconds} seconds.`, }, @@ -130,12 +129,12 @@ export async function action(args: ActionFunctionArgs) { ); } } else { - return json({ message: "forbidden" }, { status: 403, headers }); + return Response.json({ message: "forbidden" }, { status: 403, headers }); } } else if (decision.isErrored()) { console.error("Arcjet error:", decision.reason); if (decision.reason.message == "[unauthenticated] invalid key") { - return json( + return Response.json( { message: "invalid Arcjet key. Is the ARCJET_KEY environment variable set?", @@ -143,11 +142,14 @@ export async function action(args: ActionFunctionArgs) { { status: 500, headers }, ); } else { - return json({ message: "internal server error" }, { status: 500 }); + return Response.json( + { message: "internal server error" }, + { status: 500 }, + ); } } - return json( + return Response.json( { message: `HTTP 200: OK. ${remaining} requests remaining. ${message}` }, { status: 200, headers }, ); diff --git a/app/routes/sensitive-info._index.tsx b/app/routes/sensitive-info._index.tsx index 5d892ae..aaadff7 100644 --- a/app/routes/sensitive-info._index.tsx +++ b/app/routes/sensitive-info._index.tsx @@ -1,6 +1,5 @@ import { sensitiveInfo } from "@arcjet/remix"; import type { ActionFunctionArgs, MetaFunction } from "@remix-run/node"; -import { json } from "@remix-run/node"; import { Form, Link, @@ -53,10 +52,10 @@ export async function action(args: ActionFunctionArgs) { const errors = { supportMessage: "please do not include credit card numbers.", }; - return json({ errors, values }, { status: 400 }); + return Response.json({ errors, values }, { status: 400 }); } else { const errors = { supportMessage: "forbidden" }; - return json({ errors, values }, { status: 403 }); + return Response.json({ errors, values }, { status: 403 }); } } else if (decision.isErrored()) { console.error("Arcjet error:", decision.reason); @@ -65,10 +64,16 @@ export async function action(args: ActionFunctionArgs) { supportMessage: "invalid Arcjet key. Is the ARCJET_KEY environment variable set?", }; - return json({ errors, values: { supportMessage } }, { status: 500 }); + return Response.json( + { errors, values: { supportMessage } }, + { status: 500 }, + ); } else { const errors = { supportMessage: "internal server error" }; - return json({ errors, values: { supportMessage } }, { status: 500 }); + return Response.json( + { errors, values: { supportMessage } }, + { status: 500 }, + ); } } diff --git a/app/routes/signup._index.tsx b/app/routes/signup._index.tsx index 5f9a265..d8bf2c6 100644 --- a/app/routes/signup._index.tsx +++ b/app/routes/signup._index.tsx @@ -1,6 +1,5 @@ import { protectSignup } from "@arcjet/remix"; import type { ActionFunctionArgs, MetaFunction } from "@remix-run/node"; -import { json } from "@remix-run/node"; import { Form, Link, @@ -93,13 +92,13 @@ export async function action(args: ActionFunctionArgs) { } const errors = { email: message }; - return json({ errors, values }, { status: 400 }); + return Response.json({ errors, values }, { status: 400 }); } else if (decision.reason.isRateLimit()) { const reset = decision.reason.resetTime; if (reset === undefined) { const errors = { email: "too many requests. Please try again later." }; - return json({ errors, values }, { status: 429 }); + return Response.json({ errors, values }, { status: 429 }); } // Calculate number of seconds between reset Date and now @@ -110,16 +109,16 @@ export async function action(args: ActionFunctionArgs) { const errors = { email: `too many requests. Please try again in ${minutes} minutes.`, }; - return json({ errors, values }, { status: 429 }); + return Response.json({ errors, values }, { status: 429 }); } else { const errors = { email: `too many requests. Please try again in ${seconds} seconds.`, }; - return json({ errors, values }, { status: 429 }); + return Response.json({ errors, values }, { status: 429 }); } } else { const errors = { email: "forbidden" }; - return json({ errors, values }, { status: 403 }); + return Response.json({ errors, values }, { status: 403 }); } } else if (decision.isErrored()) { console.error("Arcjet error:", decision.reason); @@ -128,10 +127,10 @@ export async function action(args: ActionFunctionArgs) { email: "invalid Arcjet key. Is the ARCJET_KEY environment variable set?", }; - return json({ errors, values: { email } }, { status: 500 }); + return Response.json({ errors, values: { email } }, { status: 500 }); } else { const errors = { email: "internal server error" }; - return json({ errors, values: { email } }, { status: 500 }); + return Response.json({ errors, values: { email } }, { status: 500 }); } }