arcjet-js
arcjet-js copied to clipboard
Support for Nuxt framework
The Arcjet Node SDK doesn't currently support the Nuxt framework.
For API routes, Nuxt uses event handlers which receive an event object. This is similar to what Arcjet is expecting as ArcjetNodeRequest
, but isn't fully compatible.
import arcjet from "@arcjet/node";
const aj = arcjet({
key: "ajkey_test",
rules: [],
});
export default defineEventHandler(async (event) => {
const decision = await aj.protect(event);
return {
hello: "world",
};
});
Errors with:
Argument of type 'H3Event<EventHandlerRequest>' is not assignable to parameter of type 'ArcjetNodeRequest'.
Types of property 'headers' are incompatible.
Type 'Headers' is not assignable to type 'Record<string, string | string[] | undefined>'.
Index signature for type 'string' is missing in type 'Headers'.ts(2345)
This should probably be a new SDK specifically for Nuxt because it also has concepts like server middleware and server plugins. Creating a server plugin for Nitro would give us "free" support for that as an independenty web server, but we'd need to be able to propagate the decision back into the application.