ItzNotABug / appexpress

An express.js like framework for Appwrite Functions, enabling super-easy navigation!
Apache License 2.0
39 stars 4 forks source link

Improved Middleware #22

Closed ItzNotABug closed 4 months ago

ItzNotABug commented 4 months ago

Current middleware behaviour only allows to add a interceptor for incoming requests. This PR adds support to intercept the outgoing responses too.

The middleware behaviour is compatible with the previous implementation.

Example - Remove cookies from request & response.

appExpress.middleware({
  incoming: (req) => delete req.headers.cookie,
  outgoing: (_, interceptor) => delete interceptor.headers.cookie,
});

The interceptor contains the processed body which could be a String or a Buffer, statusCode & the headers.