Skip to content

Convert SSR example to dynamic HTTP-served first paint - #22

Merged
SeanTAllen merged 2 commits into
mainfrom
sean/dynamic-ssr-example
Mar 13, 2026
Merged

SeanTAllen merged 2 commits into
mainfrom
sean/dynamic-ssr-example

Conversation

@SeanTAllen

Copy link
Copy Markdown
Member

Replaces the static index.html in the SSR example with a hobby HTTP server that dynamically renders the initial page using PageRenderer.

A hobby HTTP server on port 8085 handles two routes: GET / calls PageRenderer.render(factory) to produce the counter's HTML at request time and serves it in a full page shell, and GET /client/* serves the JS client bundle via ServeFiles. The WebSocket server on port 8084 continues handling live updates. The factory is shared between both servers so the pre-rendered and live views always match.

The SSR example no longer needs a separate python HTTP server — just run the binary and visit http://localhost:8085/.

Closes #19

The SSR example previously served a static index.html with hardcoded
pre-rendered content, requiring a separate python HTTP server. Now that
mare 0.2.0 and hobby 0.2.1 share a compatible lori version, the example
uses hobby to serve the initial page dynamically.

A hobby HTTP server on port 8085 handles GET / by calling
PageRenderer.render(factory) to produce the counter HTML at request
time, embedding it in a full page shell with the JS client script tag.
It also serves the JS client bundle via ServeFiles on /client/*. The
WebSocket server on port 8084 continues handling live updates. The
factory is shared between both servers so the pre-rendered and live
views always match.

Closes #19
@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Mar 13, 2026
hobby's respond_with_headers doesn't auto-set Content-Length (unlike
respond), so the caller must include it. Without it, HTTP/1.1 clients
rely on connection-close to detect end-of-body, breaking keep-alive.

Filed ponylang/hobby#36 to address this at the framework level.
@SeanTAllen
SeanTAllen merged commit 50b1b77 into main Mar 13, 2026
7 checks passed
@SeanTAllen
SeanTAllen deleted the sean/dynamic-ssr-example branch March 13, 2026 01:23
@ponylang-main ponylang-main removed the discuss during sync Should be discussed during an upcoming sync label Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add hobby HTTP server for dynamic server-rendered first paint

2 participants