@oberoncms/core
Version:
OberonCMS is a cloud deployable CMS written in typescript based on the Puck visual editor
43 lines (42 loc) • 1.1 kB
JavaScript
import { initAdapter } from "./init-adapter.js";
import { initPlugins } from "./init-plugins.js";
function handle(method, handlers, adapter) {
return async (request, { params }) => {
var _a;
const { path = [] } = await params;
const action = path == null ? void 0 : path[0];
if (!action) {
return new Response("", { status: 404 });
}
const handler = (_a = handlers[action]) == null ? void 0 : _a.call(handlers, adapter)[method];
if (!handler) {
return new Response("", { status: 405 });
}
return handler(request);
};
}
function initOberon({
config,
plugins
}) {
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
};