UNPKG

@oberoncms/core

Version:

OberonCMS is a cloud deployable CMS written in typescript based on the Puck visual editor

43 lines (42 loc) 1.06 kB
import { initAdapter } from "./init-adapter.js"; import { initPlugins } from "./init-plugins.js"; function handle(method, handlers, adapter) { return async (request, { params }) => { const { path = [] } = await params; const action = path?.[0]; if (!action) { return new Response("", { status: 404 }); } const handler = handlers[action]?.(adapter)[method]; if (!handler) { return new Response("", { status: 405 }); } return handler(request); }; } function initOberon({ config, plugins }) { console.info("Initialise Oberon"); const { versions, handlers, adapter: pluginAdapter } = initPlugins(plugins); const adapter = initAdapter({ config, versions, pluginAdapter }); const handler = { GET: handle("GET", handlers, adapter), PUT: handle("PUT", handlers, adapter), PATCH: handle("PATCH", handlers, adapter), POST: handle("POST", handlers, adapter), DELETE: handle("DELETE", handlers, adapter) }; return { handler, adapter }; } export { initOberon };