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

docs(examples): Expanded AI example with rate limit by user ID #221

Merged
merged 8 commits into from
Feb 13, 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
1 change: 1 addition & 0 deletions examples/nextjs-13-pages-wrap/.env.local.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ARCJET_KEY=
6 changes: 1 addition & 5 deletions examples/nextjs-13-pages-wrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ Route](https://nextjs.org/docs/pages/building-your-application/routing/api-route
npm ci
```

3. Add your Arcjet key to `.env.local`

```env
ARCJET_KEY=
```
3. Rename `.env.local.example` to `.env.local` and add your Arcjet key.

4. Start the dev server.

Expand Down
5 changes: 5 additions & 0 deletions examples/nextjs-13-pages-wrap/environment.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare namespace NodeJS {
export interface ProcessEnv {
readonly ARCJET_KEY: string;
}
}
5 changes: 4 additions & 1 deletion examples/nextjs-13-pages-wrap/next.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
// Disabled due to errors when building. See
// https://nextjs.org/docs/messages/failed-loading-swc
swcMinify: false,
}

module.exports = nextConfig
module.exports = nextConfig
12 changes: 6 additions & 6 deletions examples/nextjs-13-pages-wrap/package-lock.json
blaine-arcjet marked this conversation as resolved.
Show resolved Hide resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions examples/nextjs-13-pages-wrap/pages/api/arcjet-edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ 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.ARCJET_KEY!,
key: process.env.ARCJET_KEY,
rules: [
// Fixed window rate limit. Arcjet also supports sliding window and token
// bucket.
fixedWindow({
mode: "LIVE",
mode: "LIVE", // will block requests. Use "DRY_RUN" to log only
// Limiting by ip.src is the default if not specified
//characteristics: ["ip.src"],
window: "1m",
max: 1,
window: "1m", // 1 min fixed window
max: 1, // allow a single request (for demo purposes)
}),
],
});
Expand Down
10 changes: 6 additions & 4 deletions examples/nextjs-13-pages-wrap/pages/api/arcjet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ 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.ARCJET_KEY!,
key: process.env.ARCJET_KEY,
rules: [
// Fixed window rate limit. Arcjet also supports sliding window and token
// bucket.
fixedWindow({
mode: "LIVE",
mode: "LIVE", // will block requests. Use "DRY_RUN" to log only
// Limiting by ip.src is the default if not specified
//characteristics: ["ip.src"],
window: "1m",
max: 1,
window: "1m", // 1 min fixed window
max: 1, // allow a single request (for demo purposes)
}),
],
});
Expand Down
1 change: 1 addition & 0 deletions examples/nextjs-14-app-dir-rl/.env.local.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ARCJET_KEY=
6 changes: 1 addition & 5 deletions examples/nextjs-14-app-dir-rl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ handler](https://nextjs.org/docs/app/building-your-application/routing/route-han
npm ci
```

3. Add your Arcjet key to `.env.local`

```env
ARCJET_KEY=
```
3. Rename `.env.local.example` to `.env.local` and add your Arcjet key.

4. Start the dev server.

Expand Down
11 changes: 7 additions & 4 deletions examples/nextjs-14-app-dir-rl/app/api/arcjet/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ const aj = arcjet({
// See: https://nextjs.org/docs/app/building-your-application/configuring/environment-variables
key: process.env.ARCJET_KEY!,
rules: [
// Fixed window rate limit. Arcjet also supports sliding window and token
// bucket.
fixedWindow({
mode: "LIVE",
characteristics: ["ip.src"],
window: "1h",
max: 1,
mode: "LIVE", // will block requests. Use "DRY_RUN" to log only
// Limiting by ip.src is the default if not specified
//characteristics: ["ip.src"],
window: "1m", // 1 min fixed window
max: 1, // allow a single request (for demo purposes)
}),
],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const aj = arcjet({
key: process.env.ARCJET_KEY!,
rules: [
validateEmail({
mode: "LIVE",
block: ["NO_MX_RECORDS"],
mode: "LIVE", // will block requests. Use "DRY_RUN" to log only
block: ["NO_MX_RECORDS"], // block email addresses with no MX records
}),
],
client,
Expand Down
5 changes: 5 additions & 0 deletions examples/nextjs-14-app-dir-rl/environment.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare namespace NodeJS {
export interface ProcessEnv {
readonly ARCJET_KEY: string;
}
}
120 changes: 52 additions & 68 deletions examples/nextjs-14-app-dir-rl/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading