mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-19 20:31:33 +00:00
* refactor(extensions): remove dead QA and utility exports * refactor(extensions): trim Matrix QA internal exports * chore(deadcode): refresh extension export baseline * chore(ci): reconcile deadcode and LOC baselines * chore(deadcode): refresh baseline after main advance * chore(deadcode): refresh baseline after main advance * refactor(plugins): keep channel snapshot type private * fix(ci): align Linux deadcode baseline
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
// Plugin HTTP route adapter for serving approved custom-widget assets.
|
|
//
|
|
// Registered with `auth:"plugin"` because sandboxed iframes carry no device
|
|
// token. The authenticated gateway mints a scoped asset capability first; the
|
|
// route validates it on every request. This adapter only translates the request;
|
|
// all capability, jail, approval, and header logic lives in `serve.ts`.
|
|
|
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
import { serveWidgetAsset, WIDGETS_ROUTE_PREFIX } from "./serve.js";
|
|
import type { WorkspaceStore } from "./store.js";
|
|
|
|
export { WIDGETS_ROUTE_PREFIX };
|
|
|
|
type WidgetHttpRouteHandler = {
|
|
handleHttpRequest: (req: IncomingMessage, res: ServerResponse) => Promise<boolean>;
|
|
};
|
|
|
|
/** Creates the HTTP route handler bound to the shared workspace store. */
|
|
export function createWidgetHttpRouteHandler(params: {
|
|
store: WorkspaceStore;
|
|
stateDir?: string;
|
|
}): WidgetHttpRouteHandler {
|
|
return {
|
|
async handleHttpRequest(req, res) {
|
|
const url = new URL(req.url ?? "/", "http://localhost");
|
|
return await serveWidgetAsset({ method: req.method, pathname: url.pathname }, res, {
|
|
store: params.store,
|
|
...(params.stateDir ? { stateDir: params.stateDir } : {}),
|
|
});
|
|
},
|
|
};
|
|
}
|