Core
Framework v2.x
2

register() #

Available since 2.8.0

Registers a new pipe on an event.

This method can only be used before the application is started.

Copied to clipboard!
register(event: string, handler: PipeEventHandler): void

Argument Type Description
event
string
Event name
handler
PipeEventHandler
Function to execute when the event is triggered

Usage #

Copied to clipboard!
app.pipe.register('server:afterNow', async (request: KuzzleRequest) => {
  request.result.now = (new Date()).toUTCString();

  return request;
});

Strong typing #

It's possible to specify the arguments with whom the handler will be called.

This will also ensure that the first argument is returned at the end of the pipe handler.

Copied to clipboard!
type EventGenericDocumentAfterWrite = {
  name: 'generic:document:afterWrite';

  args: [Document[], KuzzleRequest];
}

app.pipe.register<EventGenericDocumentAfterWrite>(
  'generic:document:afterWrite',
  async (documents: Document[], request: KuzzleRequest) => {
    app.log.error(documents);

    return documents;
  });