-
Notifications
You must be signed in to change notification settings - Fork 11
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
Support for Astro #1075
Comments
|
The unfortunate thing about this is that it seems like Astro handles rendering modes transparently and provides a |
Yes. It didn't seem right to use one of the other adapters, but using
import { defineConfig } from 'astro/config';
import vercel from "@astrojs/vercel/serverless";
// https://astro.build/config
export default defineConfig({
output: "server",
adapter: vercel()
});
import { defineMiddleware } from "astro:middleware";
import arcjet, { shield } from "@arcjet/next";
const aj = arcjet({
// Get your site key from https://app.arcjet.com
// and set it as an environment variable rather than hard coding.
key: "ajkey_01hm7kbgdaexeambd6w9fdpy8x",
rules: [
// Protect against common attacks with Arcjet Shield
shield({
mode: "DRY_RUN", // Change to "LIVE" to block requests
}),
],
});
// `context` and `next` are automatically typed
export const onRequest = defineMiddleware(async (context, next) => {
const decision = await aj.protect(context.request);
console.log(decision)
return next();
}); Result:
|
Yeah, I figured that next or another |
Astro allows middleware and provides the request information in the
context
. Per the docs, this is a standard Request object.If we try to pass this through to
aj.protect
there is a type error:Note that Astro supports several rendering modes, including static (where middleware doesn't make sense) as well as multiple runtime adapters. So we'll need to make it clear that we require server mode otherwise you get this warning:
The text was updated successfully, but these errors were encountered: