Skip to content

Commit

Permalink
Fixed middleware data return
Browse files Browse the repository at this point in the history
  • Loading branch information
GrzegorzManiak committed Jun 4, 2024
1 parent c7ad291 commit b1465a2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "noise_validator",
"version": "1.2.10",
"version": "1.2.11",
"main": "./src/index.ts",
"license": "MIT",
"author": {
Expand Down
7 changes: 6 additions & 1 deletion src/binder/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,15 @@ const validate = async <
if (!middleware.overall_success) return { ...middleware, ...middleware_return, success: false };
const validated = await validate_binder_request(request, schemas, route.path);

// -- Extract the data from the middleware
const middleware_data = Object.keys(middleware.data).reduce((acc: Record<string, unknown>, key) => {
acc[key] = middleware.data[key].data;
return acc;
}, {});

// -- Return the validated data
return {
middleware: middleware.data,
middleware: middleware_data,
body: validated.body,
query: validated.query,
headers: validated.headers,
Expand Down
6 changes: 3 additions & 3 deletions tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const route = new nv.Route(server, '/test');
class MW extends nv.GenericMiddleware {
protected handler = async () => {
console.log('Middleware executed');
throw new MiddlewareExecutionError('Middleware error');
return { 'a': 'test' }
}
}

Expand All @@ -28,9 +28,9 @@ nv.Binder(route, 'GET', {
test: MW,
}
}, async ({

middleware
}) => {
console.log('Route executed');
console.log(middleware.test);
});


Expand Down

0 comments on commit b1465a2

Please sign in to comment.