airbnb / hypernova

A service for server-side rendering your JavaScript views
MIT License
5.82k stars 208 forks source link

Add middlewares to the config. (This can be useful if you want to pro… #187

Open denimamab opened 2 years ago

denimamab commented 2 years ago

…cess some treatment after the body-parser.)

ljharb commented 2 years ago

Can you elaborate about your use cases?

denimamab commented 2 years ago

@ljharb Hello,

The use case is to implement a middleware that can read the body for each job and compare the version number with the hypernova-server version number. That assure to re-render the component if the cache version is not valid with the HS version and serve the urls for the right assets (js + css) in the meta field.

Monolithe: construct the jobs to process (if the job is already in a distributed cache [Eg. redis] we set a flag that the job is already in cache and here is the cache version => hypernova-server intercept these jobs and should process only the jobs that are not cache valid.

This answers the problem of cache invalidation strategy when deploying newer version of hypernova-service.

nksfrank commented 2 years ago

you can access the express app by passing in a onServer callback to hypernova(config, onServer), that way you can add your middlewares after body-parser https://github.com/airbnb/hypernova/blob/master/src/worker.js#L124