Add heartbeat middleware