Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(examples): Encourage use of environment variables for keys #139

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion arcjet-next/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ import arcjet from "@arcjet/next";
import { NextApiRequest, NextApiResponse } from "next";

const aj = arcjet({
key: "ajkey_yourkey",
// 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,
rules: [],
});

Expand Down
5 changes: 4 additions & 1 deletion arcjet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ import arcjet, { createRemoteClient, defaultBaseUrl } from "arcjet";
import { createConnectTransport } from "@connectrpc/connect-node";

const aj = arcjet({
key: "ajkey_mykey",
// 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,
rules: [],
client: createRemoteClient({
transport: createConnectTransport({
Expand Down
12 changes: 9 additions & 3 deletions examples/nextjs-13-pages-wrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@ Route](https://nextjs.org/docs/pages/building-your-application/routing/api-route
npm ci
```

3. Start the dev server.
3. Add your Arcjet key to `.env.local`

```env
AJ_KEY=
```

4. Start the dev server.

```bash
npm run dev
```

4. Visit `http://localhost:3000/api/arcjet`.
5. Refresh the page to trigger the rate limit.
5. Visit `http://localhost:3000/api/arcjet`.
6. Refresh the page to trigger the rate limit.
8 changes: 5 additions & 3 deletions examples/nextjs-13-pages-wrap/pages/api/arcjet-edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ export const config = {
};

const aj = arcjet({
// mark
key: "ajkey_yourkey",
// 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!,
rules: [
rateLimit({
mode: "LIVE",
Expand All @@ -25,4 +27,4 @@ export default withArcjet(aj, async function handler(req: NextRequest) {
return NextResponse.json({
message: "Hello world",
});
});
});
8 changes: 5 additions & 3 deletions examples/nextjs-13-pages-wrap/pages/api/arcjet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import arcjet, { rateLimit, withArcjet } from "@arcjet/next";
import type { NextApiRequest, NextApiResponse } from "next";

const aj = arcjet({
// mark
key: "ajkey_yourkey",
// 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!,
rules: [
rateLimit({
mode: "LIVE",
Expand All @@ -22,4 +24,4 @@ export default withArcjet(
async function handler(req: NextApiRequest, res: NextApiResponse) {
res.status(200).json({ name: "Hello world" });
},
);
);
12 changes: 9 additions & 3 deletions examples/nextjs-14-app-dir-rl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@ handler](https://nextjs.org/docs/app/building-your-application/routing/route-han
npm ci
```

3. Start the dev server.
3. Add your Arcjet key to `.env.local`

```env
AJ_KEY=
```

4. Start the dev server.

```bash
npm run dev
```

4. Visit `http://localhost:3000/api/arcjet`.
5. Refresh the page to trigger the rate limit.
5. Visit `http://localhost:3000/api/arcjet`.
6. Refresh the page to trigger the rate limit.
7 changes: 5 additions & 2 deletions examples/nextjs-14-app-dir-rl/app/api/arcjet/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import arcjet, { rateLimit } from "@arcjet/next";
import { NextResponse } from "next/server";

const aj = arcjet({
key: "ajkey_yourkey",
// 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!,
rules: [
rateLimit({
mode: "LIVE",
Expand Down Expand Up @@ -30,4 +33,4 @@ export async function GET(req: Request) {
}

return NextResponse.json({ message: "Hello World" });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ const client = createNextRemoteClient({
});

const aj = arcjet({
key: "ajkey_yourkey",
// 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!,
rules: [
validateEmail({
mode: "LIVE",
Expand All @@ -37,4 +40,4 @@ export async function GET(req: Request) {
}

return NextResponse.json({ message: "Hello World" });
}
}
7 changes: 5 additions & 2 deletions examples/nextjs-14-app-dir-rl/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ export const config = {
};

const aj = arcjet({
key: "ajkey_yourkey",
// 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!,
rules: [],
});

export default createMiddleware(aj);
export default createMiddleware(aj);
12 changes: 9 additions & 3 deletions examples/nextjs-14-app-dir-validate-email/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@ handler](https://nextjs.org/docs/app/building-your-application/routing/route-han
npm ci
```

3. Start the dev server.
3. Add your Arcjet key to `.env.local`

```env
AJ_KEY=
```

4. Start the dev server.

```bash
npm run dev
```

4. Visit `http://localhost:3000/api/arcjet`.
5. Refresh the page to see the email verification fail due to no MX records
5. Visit `http://localhost:3000/api/arcjet`.
6. Refresh the page to see the email verification fail due to no MX records
existing on the domain.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import arcjet, { validateEmail } from "@arcjet/next";
import { NextResponse } from "next/server";

const aj = arcjet({
key: "ajkey_yourkey",
// 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!,
rules: [
validateEmail({
mode: "LIVE",
Expand Down Expand Up @@ -30,4 +33,4 @@ export async function GET(req: Request) {
return NextResponse.json({
message: "Hello world",
});
}
}
3 changes: 2 additions & 1 deletion examples/nextjs-14-openai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ uses the OpenAI chat API.
npm ci
```

3. Add your OpenAI key to `.env.local`
3. Add your Arcjet & OpenAI keys to `.env.local`

```env
AJ_KEY=
OPENAI_API_KEY=
```

Expand Down
7 changes: 5 additions & 2 deletions examples/nextjs-14-openai/app/api/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import { promptTokensEstimate } from "openai-chat-tokens";

// Arcjet rate limit rule
const aj = arcjet({
key: "ajkey_yourkey",
// 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!,
rules: [
rateLimit({
mode: "LIVE",
Expand Down Expand Up @@ -68,4 +71,4 @@ export async function POST(req: Request) {
const stream = OpenAIStream(response);
// Respond with the stream
return new StreamingTextResponse(stream);
}
}
12 changes: 9 additions & 3 deletions examples/nextjs-14-pages-wrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@ Route](https://nextjs.org/docs/pages/building-your-application/routing/api-route
npm ci
```

3. Start the dev server.
3. Add your Arcjet key to `.env.local`

```env
AJ_KEY=
```

4. Start the dev server.

```bash
npm run dev
```

4. Visit `http://localhost:3000/api/arcjet`.
5. Refresh the page to trigger the rate limit.
5. Visit `http://localhost:3000/api/arcjet`.
6. Refresh the page to trigger the rate limit.
8 changes: 5 additions & 3 deletions examples/nextjs-14-pages-wrap/pages/api/arcjet-edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ export const config = {
};

const aj = arcjet({
// mark
key: "ajkey_yourkey",
// 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!,
rules: [
rateLimit({
mode: "LIVE",
Expand All @@ -25,4 +27,4 @@ export default withArcjet(aj, async function handler(req: NextRequest) {
return NextResponse.json({
message: "Hello world",
});
});
});
8 changes: 5 additions & 3 deletions examples/nextjs-14-pages-wrap/pages/api/arcjet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import arcjet, { rateLimit, withArcjet } from "@arcjet/next";
import type { NextApiRequest, NextApiResponse } from "next";

const aj = arcjet({
// mark
key: "ajkey_yourkey",
// 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!,
rules: [
rateLimit({
mode: "LIVE",
Expand All @@ -22,4 +24,4 @@ export default withArcjet(
async function handler(req: NextApiRequest, res: NextApiResponse) {
res.status(200).json({ name: "Hello world" });
},
);
);