@powership/server
Version:
29 lines • 716 B
JavaScript
import { createHandler } from "./createHandler.mjs";
import { createRouteMatcher } from "./routeMatch.mjs";
export function createRouteHandler(path, handler, data) {
//
const matcher = createRouteMatcher(path);
return createHandler(path, {
async onRequest(request, {
response,
app,
close
}) {
const {
pathname: request_path
} = request;
const params = matcher.match(request_path);
if (!params) return;
const context = {
path: request_path,
request,
response,
close,
app,
params
};
await handler.call(context, context);
}
}, data);
}
//# sourceMappingURL=createRouteHandler.mjs.map