On this page
The static-file primitives both local servers share: how a file's content type is decided, and what counts as a path inside the tree being served.
#internal/blog/serving
#internal/blog/serving
Package serving carries the static-file primitives shared by the two local servers.
The authoring app and the assembly preview both hand bytes off a disk tree to a browser on loopback. Two questions are the same in both -- what content type a file is served as, and what counts as a path inside the served root -- so they are answered here once rather than twice, slightly differently.
Both servers bind [Host] and nothing else. Neither authenticates anything: the editor writes working trees and the preview serves an unreleased site, so the bind address is not configurable.
#Host
const Host = "127.0.0.1"Host is the one address either server binds.
#ContentTypes
var ContentTypes = map[string]string{ContentTypes are the content types the platform's MIME database gets wrong often enough to be worth stating. Anything absent falls through to the platform database and then to the generic binary type.
#ContentType
func ContentType(path string) stringContentType returns the content type path is served as.
#ResolveUnder
func ResolveUnder(root string, rel string) (string, bool)ResolveUnder joins rel under root, reporting false when the result escapes root.
Symlinks are resolved before the containment test, so a link inside the served tree cannot be followed out of it. The caller decides what an escape looks like on the wire -- the editor answers a refusal, the preview answers its 404 page.