This middleware adds so-called Incremental Static Regeneration to your server.
npm i incremental-regeneration
import incrementalRegeneration from 'incremental-regeneration';
// define your server
const server = ...
const myFunctionThatRendersPage = (req, res) => void;
server.use(incrementalRegeneration({
middleware: myFunctionThatRendersPage,
revalidateTime: 10
}))
//
revalidateTime
(in seconds): time boundary after which the resource will be regenerated
middleware
: function that matches type (req: http.ClientRequest, res: http.ServerResponse) => void. This function is expected to render a response and write it to res param.