class

Hwaro::Services::BasePathHandler

Inherits HTTP::Handler < Reference < Object

Mounts the built output under base_url's path component.

hwaro serve --base-url http://localhost:3000/myblog/ builds a site whose every link, stylesheet and script is /myblog/…, but the dev server used to answer only at / — so the homepage loaded unstyled and every internal link 404'd. Requests carrying the prefix now have it stripped before routing, and Location headers produced downstream get it added back so the address bar stays coherent.

Deliberately lenient: an unprefixed request is passed through untouched rather than 404'd, so /css/style.css typed by hand (or requested by an older cached page) still resolves. Only the bare root is redirected, so --open and manual browsing land on the prefixed site.

A no-op when base_path is "" — the default, since serve derives base_url from host:port unless --base-url says otherwise.

Constructors

new(base_path : String)

Normalised here rather than assumed: a trailing slash made every starts_with?("#{@base_path}/") test unmatchable and produced Location: /myblog//, so the documented contract is now enforced.

Source

Instance methods

call(context)
Source