Skip to main content
Glama
handler.js1.62 kB
// src/adapter/cloudflare-pages/handler.ts import { Context } from "../../context.js"; import { HTTPException } from "../../http-exception.js"; var handle = (app) => (eventContext) => { return app.fetch( eventContext.request, { ...eventContext.env, eventContext }, { waitUntil: eventContext.waitUntil, passThroughOnException: eventContext.passThroughOnException, props: {} } ); }; function handleMiddleware(middleware) { return async (executionCtx) => { const context = new Context(executionCtx.request, { env: { ...executionCtx.env, eventContext: executionCtx }, executionCtx }); let response = void 0; try { response = await middleware(context, async () => { try { context.res = await executionCtx.next(); } catch (error) { if (error instanceof Error) { context.error = error; } else { throw error; } } }); } catch (error) { if (error instanceof Error) { context.error = error; } else { throw error; } } if (response) { return response; } if (context.error instanceof HTTPException) { return context.error.getResponse(); } if (context.error) { throw context.error; } return context.res; }; } var serveStatic = () => { return async (c) => { const env = c.env; const res = await env.ASSETS.fetch(c.req.raw); if (res.status === 404) { return c.notFound(); } return res; }; }; export { handle, handleMiddleware, serveStatic };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Valerio357/bet-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server