heartbeat middleware