(
handlerOrOptions:
| CloudflareOptions
| ((context: EventPluginContext<Env, Params, Data, PluginParams>) => CloudflareOptions),
)
| 34 | * @returns A plugin function that can be used in Cloudflare Pages. |
| 35 | */ |
| 36 | export function sentryPagesPlugin< |
| 37 | Env = unknown, |
| 38 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 39 | Params extends string = any, |
| 40 | Data extends Record<string, unknown> = Record<string, unknown>, |
| 41 | // Although it is not ideal to use `any` here, it makes usage more flexible for different setups. |
| 42 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 43 | PluginParams = any, |
| 44 | >( |
| 45 | handlerOrOptions: |
| 46 | | CloudflareOptions |
| 47 | | ((context: EventPluginContext<Env, Params, Data, PluginParams>) => CloudflareOptions), |
| 48 | ): PagesPluginFunction<Env, Params, Data, PluginParams> { |
| 49 | setAsyncLocalStorageAsyncContextStrategy(); |
| 50 | return context => { |
| 51 | if (context.request.method === 'OPTIONS' || context.request.method === 'HEAD') { |
| 52 | return context.next(); |
| 53 | } |
| 54 | |
| 55 | const options = typeof handlerOrOptions === 'function' ? handlerOrOptions(context) : handlerOrOptions; |
| 56 | return wrapRequestHandler({ options, request: context.request, context: { ...context, props: {} } }, () => |
| 57 | context.next(), |
| 58 | ); |
| 59 | }; |
| 60 | } |
no test coverage detected