@hattip/compose
Advanced tools
Comparing version
@@ -8,11 +8,2 @@ // src/index.ts | ||
const flatHandlers = handlers.flat().filter(Boolean); | ||
flatHandlers.unshift((context) => { | ||
context.url = new URL(context.request.url); | ||
context.method = context.request.method; | ||
context.locals = {}; | ||
context.handleError = (error) => { | ||
console.error(error); | ||
return new Response("Internal Server Error", { status: 500 }); | ||
}; | ||
}); | ||
return flatHandlers.map(wrap).reduceRight((prev, current) => { | ||
@@ -27,3 +18,15 @@ return async (context) => { | ||
function compose(...handlers) { | ||
return composePartial([...handlers, finalHandler]); | ||
return composePartial([ | ||
(context) => { | ||
context.url = new URL(context.request.url); | ||
context.method = context.request.method; | ||
context.locals = {}; | ||
context.handleError = (error) => { | ||
console.error(error); | ||
return new Response("Internal Server Error", { status: 500 }); | ||
}; | ||
}, | ||
...handlers, | ||
finalHandler | ||
]); | ||
} | ||
@@ -30,0 +33,0 @@ function wrap(handler) { |
{ | ||
"name": "@hattip/compose", | ||
"version": "0.0.16", | ||
"version": "0.0.17", | ||
"type": "module", | ||
@@ -12,3 +12,3 @@ "description": "Middleware system for HatTip", | ||
"dependencies": { | ||
"@hattip/core": "0.0.16" | ||
"@hattip/core": "0.0.17" | ||
}, | ||
@@ -15,0 +15,0 @@ "devDependencies": { |
8691
0.09%93
3.33%+ Added
- Removed
Updated