Command Palette

Search for a command to run...

Hectal
Phase 23: Build, Deploy and Run in Production
React · Exercise 2 of 5 PreviousNext
Intermediate

Write the SPA fallback rule

Finish host(path), a model of a static host serving dist/. It returns a string:

- a file that exists in dist → "200 " + file (and / means /index.html);

- a missing path under /assets/ → "404" (a missing JS file must never get HTML);

- any other path → "200 /index.html" (the SPA fallback, so the router can handle it).

The input #path, the button #go and the result #result are already wired up.

What Check tests

  1. A real asset is served as itself
  2. / serves /index.html
  3. A deep link like /products/42 falls back to index.html
  4. A missing asset is an honest 404
  5. Other real files still work

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.