Marketplace móvil para negocios locales mexicanos. Estructura inicial: - apps/backend (NestJS API) - apps/frontend (React Web) - apps/mobile (Expo/React Native) - apps/mcp-server (Claude MCP Server) - apps/whatsapp-service (WhatsApp Business API) - database/ (PostgreSQL DDL) - docs/ (Documentación) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
// src/compose.ts
|
|
var compose = (middleware, onError, onNotFound) => {
|
|
return (context, next) => {
|
|
let index = -1;
|
|
return dispatch(0);
|
|
async function dispatch(i) {
|
|
if (i <= index) {
|
|
throw new Error("next() called multiple times");
|
|
}
|
|
index = i;
|
|
let res;
|
|
let isError = false;
|
|
let handler;
|
|
if (middleware[i]) {
|
|
handler = middleware[i][0][0];
|
|
context.req.routeIndex = i;
|
|
} else {
|
|
handler = i === middleware.length && next || void 0;
|
|
}
|
|
if (handler) {
|
|
try {
|
|
res = await handler(context, () => dispatch(i + 1));
|
|
} catch (err) {
|
|
if (err instanceof Error && onError) {
|
|
context.error = err;
|
|
res = await onError(err, context);
|
|
isError = true;
|
|
} else {
|
|
throw err;
|
|
}
|
|
}
|
|
} else {
|
|
if (context.finalized === false && onNotFound) {
|
|
res = await onNotFound(context);
|
|
}
|
|
}
|
|
if (res && (context.finalized === false || isError)) {
|
|
context.res = res;
|
|
}
|
|
return context;
|
|
}
|
|
};
|
|
};
|
|
export {
|
|
compose
|
|
};
|