import { createApi } from './api.mjs' export default { async fetch(request) { try { const headers = request.headers const uri = new URL(request.url) const { origin, pathname } = new URL(uri.pathname.substring(1)) const api = createApi(origin, { headers }) const payload = await api[pathname][request.method](uri.searchParams) return Response.json(payload) } catch (error) { return Response.json({ error: error.message }) } } }