All files / src/hooks useWakeApi.ts

66.66% Statements 2/3
100% Branches 0/0
66.66% Functions 2/3
100% Lines 2/2

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19                            1x 1x      
import { useEffect } from 'react'
 
import { config } from '@/lib/config'
 
/**
 * Starts waking the API the moment a public screen opens.
 *
 * The free Render instance takes about a minute to come back from sleep. A
 * visitor spends some of that minute reading the page or typing an e-mail, so
 * asking `/health` on arrival means the server is often up by the time they
 * press anything. Fire and forget: the answer is not used, a failure is not an
 * error, and no cookie goes with it.
 */
export function useWakeApi() {
  useEffect(() => {
    void fetch(`${config.apiBaseUrl}/health`, { credentials: 'omit' }).catch(() => undefined)
  }, [])
}