1.0.0-alpha.28 • Published 9 months ago

@arcjet/decorate v1.0.0-alpha.28

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
9 months ago

@arcjet/decorate

Arcjet utilities for decorating responses with information.

Installation

npm install -S @arcjet/decorate

Example

import arcjet, { fixedWindow } from "@arcjet/next";
import { setRateLimitHeaders } from "@arcjet/decorate";
import { NextApiRequest, NextApiResponse } from "next";

const aj = arcjet({
  key: process.env.ARCJET_KEY!, // Get your site key from https://app.arcjet.com
  rules: [
    // Create a fixed window rate limit. Other algorithms are supported.
    fixedWindow({
      mode: "LIVE", // will block requests. Use "DRY_RUN" to log only
      window: "1m", // 1 min fixed window
      max: 1, // allow a single request
    }),
  ],
});

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

  setRateLimitHeaders(res, decision);

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

  res.status(200).json({ name: "Hello world" });
}

License

Licensed under the Apache License, Version 2.0.

1.0.0-alpha.28

9 months ago

1.0.0-alpha.27

10 months ago

1.0.0-alpha.26

10 months ago

1.0.0-alpha.23

11 months ago

1.0.0-alpha.25

10 months ago

1.0.0-alpha.24

10 months ago

1.0.0-alpha.19

12 months ago

1.0.0-alpha.21

11 months ago

1.0.0-alpha.20

12 months ago

1.0.0-alpha.16

1 year ago

1.0.0-alpha.15

1 year ago

1.0.0-alpha.18

1 year ago

1.0.0-alpha.17

1 year ago

1.0.0-alpha.22

11 months ago

1.0.0-alpha.14

1 year ago

1.0.0-alpha.13

1 year ago

1.0.0-alpha.12

1 year ago

1.0.0-alpha.11

1 year ago

1.0.0-alpha.10

1 year ago

1.0.0-alpha.9

1 year ago