elastic / kibana

Your window into the Elastic Stack
https://www.elastic.co/products/kibana
Other
19.63k stars 8.22k forks source link

Support registration HTTP Middleware #76897

Closed aimuz closed 8 months ago

aimuz commented 4 years ago

Describe the feature: I'm developing a plug-in, but I don't find support for middleware functionality. The only thing I found was core.http.registerOnPreResponse But this interface is too limited to implement the function I want

I want to have an interface that enables you to override the response instead of just adding headers

core.http.registerOnPreResponse At present, the only function that can be implemented is to add a header. I think this function is incomplete.

Describe a specific use case for the feature:

core.http.use((req ,next)=>{
      const res = next(req);
      return res
})

There may be a better way Or expose the interface completely

https://github.com/hapijs/hapi/blob/master/API.md#-serverextevents

Through this interface, you can implement more powerful plug-ins

elasticmachine commented 4 years ago

Pinging @elastic/kibana-platform (Team:Platform)

pgayvallet commented 4 years ago

Not allowing to override the response body from plugin interceptors is a voluntary, opinionated decision from the kibana platform API.

Can you add more details on the usage you would need this feature for? If you only need to override your own plugin's routing behavior, a simple HOC wrapper around your route handler(s) should be sufficient:

https://github.com/elastic/kibana/blob/bf04235dae35452061cc7ea3d86d96c19a58206c/src/core/server/http/router/error_wrapper.ts#L23-L38

Or expose the interface completely

FYI, the underlying http lib used is now an implementation detail. The platform will now longer expose 'direct' access to HAPI API (or any replacement we might be using in the futur).

aimuz commented 4 years ago

In fact, I hope to use this method to customize authentication as a middleware to intercept all requests and verify whether they have been logged in

mshustov commented 4 years ago

@aimuz seems that https://github.com/elastic/kibana/pull/75538 might add such functionality