UNPKG

@paroicms/server

Version:
21 lines 1.03 kB
import { createBackendPluginService } from "../plugin-services/make-backend-plugin-service.js"; import { serve404SimpleHtml } from "./http-helpers.js"; export async function pluginPublicApiReqHandler(siteContext, httpContext) { const { req } = httpContext; const path = req.path; const prefix = "/api/plugin/"; if (!path.startsWith(prefix)) return false; const sepIndex = path.indexOf("/", prefix.length); const pluginPublicDirName = sepIndex === -1 ? path.substring(prefix.length) : path.substring(prefix.length, sepIndex); const relativePath = sepIndex === -1 ? "" : path.substring(sepIndex); const plugin = siteContext.pluginsBySlug.get(pluginPublicDirName); if (!plugin || !plugin.publicApiHandler) { serve404SimpleHtml(httpContext); return true; } const service = createBackendPluginService(siteContext, plugin); await plugin.publicApiHandler(service, httpContext, relativePath); return true; } //# sourceMappingURL=public-api.req-handler.js.map