moleculer icon indicating copy to clipboard operation
moleculer copied to clipboard

Broker middleware `call` wrapper removes context data. Cannot use ctx.meta.

Open ggondim opened this issue 1 year ago • 0 comments

Prerequisites

  • [X] I am running the latest version
  • [X] I checked the documentation and found no answer
  • [X] I checked to make sure that this issue has not already been filed
  • [X] I'm reporting the issue to the correct repository

Current Behavior

When using a custom middleware in broker, specially when defing a call wrapper exactly the way the official documentation indicates, context data appears to be removed.

For example, moleculer-web's context.meta.$statusCode doesn't work when defining the middleware.

If you remove the middleware, everything works fine.

Expected Behavior

Context data should be there after calling the action.

moleculer-web's context.meta.$statusCode should work even with middlewares.

Failure Information

Steps to Reproduce

  1. Create a call wrapper as a custom middleware exactly the way the official documentation indicates

image

  1. Use ctx.meta between actions, such as setting ctx.meta.$statusCode using moleculer-web

image

  1. Call the action, the context will be lost

Take a look at the repro steps below.

Reproduce code

Code is reproduced under this repro repo.

  1. Git clone it
  2. npm install && npm run dev
  3. curl --location 'localhost:4987/api/statusCodeTest/testNotFound' -I

You will see an HTTP 200 instead an HTTP 404 as defined in statusCode.service.ts action.

image

Context

  • Moleculer version: 0.14.31
  • NodeJS version: 19.7.0
  • Operating System: Ubuntu 22.04

ggondim avatar Sep 02 '23 20:09 ggondim