Skip to content

Commit

Permalink
docs: Rename AJ_KEY to ARCJET_KEY & switch to next.js app dir example (
Browse files Browse the repository at this point in the history
…#201)

- Replaces `AJ_KEY` with `ARCJET_KEY` to be consistent with the docs.
- Replaces the Next.js readme pages router example with an app router example because that is now the default and most common for new apps.
  • Loading branch information
davidmytton authored Feb 7, 2024
1 parent b173d83 commit 9c4da7b
Show file tree
Hide file tree
Showing 16 changed files with 24 additions and 26 deletions.
18 changes: 8 additions & 10 deletions arcjet-next/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,27 @@ npm install -S @arcjet/next

```ts
import arcjet from "@arcjet/next";
import { NextApiRequest, NextApiResponse } from "next";
import { NextResponse } from "next/server";

const aj = arcjet({
// Get your site key from https://app.arcjet.com
// and set it as an environment variable rather than hard coding.
// See: https://nextjs.org/docs/app/building-your-application/configuring/environment-variables
key: process.env.AJ_KEY,
key: process.env.ARCJET_KEY,
rules: [],
});

export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
) {
export async function GET(req: Request) {
const decision = await aj.protect(req);

if (decision.isDenied()) {
return res
.status(403)
.json({ error: "Forbidden", reason: decision.reason });
return NextResponse.json(
{ error: "Too Many Requests", reason: decision.reason },
{ status: 429 },
);
}

res.status(200).json({ name: "Hello world" });
return NextResponse.json({ message: "Hello world" });
}
```

Expand Down
2 changes: 1 addition & 1 deletion arcjet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const aj = arcjet({
// Get your site key from https://app.arcjet.com
// and set it as an environment variable rather than hard coding.
// See: https://www.npmjs.com/package/dotenv
key: process.env.AJ_KEY,
key: process.env.ARCJET_KEY,
rules: [],
client: createRemoteClient({
transport: createConnectTransport({
Expand Down
2 changes: 1 addition & 1 deletion examples/nextjs-13-pages-wrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Route](https://nextjs.org/docs/pages/building-your-application/routing/api-route
3. Add your Arcjet key to `.env.local`

```env
AJ_KEY=
ARCJET_KEY=
```

4. Start the dev server.
Expand Down
2 changes: 1 addition & 1 deletion examples/nextjs-13-pages-wrap/pages/api/arcjet-edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const aj = arcjet({
// Get your site key from https://app.arcjet.com
// and set it as an environment variable rather than hard coding.
// See: https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables
key: process.env.AJ_KEY!,
key: process.env.ARCJET_KEY!,
rules: [
fixedWindow({
mode: "LIVE",
Expand Down
2 changes: 1 addition & 1 deletion examples/nextjs-13-pages-wrap/pages/api/arcjet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const aj = arcjet({
// Get your site key from https://app.arcjet.com
// and set it as an environment variable rather than hard coding.
// See: https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables
key: process.env.AJ_KEY!,
key: process.env.ARCJET_KEY!,
rules: [
fixedWindow({
mode: "LIVE",
Expand Down
2 changes: 1 addition & 1 deletion examples/nextjs-14-app-dir-rl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ handler](https://nextjs.org/docs/app/building-your-application/routing/route-han
3. Add your Arcjet key to `.env.local`

```env
AJ_KEY=
ARCJET_KEY=
```

4. Start the dev server.
Expand Down
2 changes: 1 addition & 1 deletion examples/nextjs-14-app-dir-rl/app/api/arcjet/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const aj = arcjet({
// Get your site key from https://app.arcjet.com
// and set it as an environment variable rather than hard coding.
// See: https://nextjs.org/docs/app/building-your-application/configuring/environment-variables
key: process.env.AJ_KEY!,
key: process.env.ARCJET_KEY!,
rules: [
fixedWindow({
mode: "LIVE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const aj = arcjet({
// Get your site key from https://app.arcjet.com
// and set it as an environment variable rather than hard coding.
// See: https://nextjs.org/docs/app/building-your-application/configuring/environment-variables
key: process.env.AJ_KEY!,
key: process.env.ARCJET_KEY!,
rules: [
validateEmail({
mode: "LIVE",
Expand Down
2 changes: 1 addition & 1 deletion examples/nextjs-14-app-dir-rl/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const aj = arcjet({
// Get your site key from https://app.arcjet.com
// and set it as an environment variable rather than hard coding.
// See: https://nextjs.org/docs/app/building-your-application/configuring/environment-variables
key: process.env.AJ_KEY!,
key: process.env.ARCJET_KEY!,
rules: [],
});

Expand Down
2 changes: 1 addition & 1 deletion examples/nextjs-14-app-dir-validate-email/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ handler](https://nextjs.org/docs/app/building-your-application/routing/route-han
3. Add your Arcjet key to `.env.local`

```env
AJ_KEY=
ARCJET_KEY=
```

4. Start the dev server.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const aj = arcjet({
// Get your site key from https://app.arcjet.com
// and set it as an environment variable rather than hard coding.
// See: https://nextjs.org/docs/app/building-your-application/configuring/environment-variables
key: process.env.AJ_KEY!,
key: process.env.ARCJET_KEY!,
rules: [
validateEmail({
mode: "LIVE",
Expand Down
2 changes: 1 addition & 1 deletion examples/nextjs-14-openai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ uses the OpenAI chat API.
3. Add your Arcjet & OpenAI keys to `.env.local`

```env
AJ_KEY=
ARCJET_KEY=
OPENAI_API_KEY=
```

Expand Down
4 changes: 2 additions & 2 deletions examples/nextjs-14-openai/app/api/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const aj = arcjet({
// Get your site key from https://app.arcjet.com
// and set it as an environment variable rather than hard coding.
// See: https://nextjs.org/docs/app/building-your-application/configuring/environment-variables
key: process.env.AJ_KEY!,
key: process.env.ARCJET_KEY!,
rules: [
tokenBucket({
mode: "LIVE",
Expand Down Expand Up @@ -70,4 +70,4 @@ export async function POST(req: Request) {
const stream = OpenAIStream(response);
// Respond with the stream
return new StreamingTextResponse(stream);
}
}
2 changes: 1 addition & 1 deletion examples/nextjs-14-pages-wrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Route](https://nextjs.org/docs/pages/building-your-application/routing/api-route
3. Add your Arcjet key to `.env.local`

```env
AJ_KEY=
ARCJET_KEY=
```

4. Start the dev server.
Expand Down
2 changes: 1 addition & 1 deletion examples/nextjs-14-pages-wrap/pages/api/arcjet-edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const aj = arcjet({
// Get your site key from https://app.arcjet.com
// and set it as an environment variable rather than hard coding.
// See: https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables
key: process.env.AJ_KEY!,
key: process.env.ARCJET_KEY!,
rules: [
fixedWindow({
mode: "LIVE",
Expand Down
2 changes: 1 addition & 1 deletion examples/nextjs-14-pages-wrap/pages/api/arcjet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const aj = arcjet({
// Get your site key from https://app.arcjet.com
// and set it as an environment variable rather than hard coding.
// See: https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables
key: process.env.AJ_KEY!,
key: process.env.ARCJET_KEY!,
rules: [
fixedWindow({
mode: "LIVE",
Expand Down

0 comments on commit 9c4da7b

Please sign in to comment.