Study map · Advanced · Runs in your IDE

Practice file delivery, SSE and WebSocket.

Learn file delivery, SSE and WebSocket through three independent services. Some language journeys include a follow-up that combines all three.

01 · Learning order

Each first exercise keeps one subject

ExerciseOnly observeWhy it is separate
01 · File deliveryGET /download returns manual.txt.Focus on authority, path, limits and the file-response contract.
02 · SSEGET /events emits state: ready, then done.Focus on one-way streaming, event fields and reconnect meaning.
03 · WebSocketGET /socket sends ready and echoes text.Focus on upgrade, subprotocol and a bidirectional session.
04 · IntegrationAll three endpoints in one service.Learn composition after no capability needs to be guessed.

The integration is optional, not the starting point. Production still maps authorization, replay and session policy to the application domain.

Open the exercise

02 · Verify the behavior

Run only the check for the current exercise

Replace PORT with the printed port
curl http://127.0.0.1:PORT/download
curl -N http://127.0.0.1:PORT/events

const socket = new WebSocket(
  "ws://127.0.0.1:PORT/socket",
  "coakka.demo",
);
socket.onmessage = (event) => console.log(event.data);
socket.onopen = () => socket.send("hello");

03 · Parameters beside the example

Configure only what changes user-visible behavior

authority id
Identity connecting a file response to its configured root; it is not a filesystem descriptor.
root path
The allowed filesystem boundary. A request cannot select another absolute path.
max active files
Bounds concurrent transfers so a slow client cannot retain unlimited resources.
max file bytes
A larger file is refused instead of silently loaded or sent.
encoded path
A relative path inside the authority, selected by the application after authorization.
data
The SSE event payload.
event
An optional SSE event type for client dispatch.
id
An application cursor/identity; it does not create a replay store.
retry
An SSE client reconnect-delay hint, not a server retry.
subprotocol
The application protocol requested by the client and selected during the WebSocket handshake.

04 · Failure lookup

Start from the symptom, locate the boundary, then fix it

SymptomCommon causeResponse
File 404/refusalWrong encoded path, missing file or path outside the authority.Check business mapping and deployment; do not widen the root to hide the error.
File refused under concurrencyActive-transfer or file-size bound reached.Measure concurrency/size; reduce load or tune from evidence.
SSE stops earlyClient disconnect, write timeout or service drain.Stop the producer and release its subscription; reconnect/replay by application policy.
WebSocket does not upgradeRoute, auth/origin, subprotocol or capacity mismatch.Read the HTTP refusal and service error; do not create a fake session.
WebSocket closes after sendHandler error, message/pressure limit or peer close.Read close code, background error and limits; reconnect finitely.
TimeoutNo terminal outcome was observed within the budget.Do not assume the message was not delivered; reconcile side effects before retry.

05 · Operate the feature

Monitor behavior, not implementation details