Documentation
¶
Overview ¶
Package standalonehttp serves an HTML or JSX asset as one self-contained HTML file that opens from disk with the network off (#2530).
Every content route an asset is downloaded from has a .../standalone beside it. The route reads the asset through its content route, in-process and with the caller's own request, so who may download the file is exactly who may read the asset, by the same checks, and the file inlines only what that read already hands the caller. internal/standalone then inlines what the document loads: the platform's served runtimes and the asset's declared references are read from the platform's own routes with a request that carries nothing of the caller's, and a file on another host is fetched through the egress guard.
An asset that reads the platform's data while it renders is answered 409 with what it reads, and the portal offers the stored source instead (?source=stored on the content route, pkg/portal).
Index ¶
Constants ¶
const ( // MaxDocumentBytes bounds the asset a route reads to export. MaxDocumentBytes = 32 << 20 // NoticesHeader carries the files the export left as their URLs, as // URL-escaped JSON, so the portal can name them beside the download. NoticesHeader = "X-Standalone-Notices" // DefaultConcurrency is how many exports this replica builds at once. // An export can fetch up to its byte bound from other hosts and compile a // bundle, so a signed-in caller cannot start them without limit. DefaultConcurrency = 4 )
Variables ¶
var Routes = []Route{ {Pattern: "GET /api/v1/portal/assets/{id}/standalone", Content: "/api/v1/portal/assets/{id}/content"}, {Pattern: "GET /portal/view/{token}/standalone", Content: "/portal/view/{token}/content", Public: true}, {Pattern: "GET /portal/view/{token}/items/{assetId}/standalone", Content: "/portal/view/{token}/items/{assetId}/content", Public: true}, }
Routes are the standalone routes, each beside the content route it reads.
Functions ¶
func MountFor ¶
MountFor mounts the standalone routes on mux, fetching other hosts through an egress guard that admits no private address, with public routes limited per client. The routes read through mux, so it is called once the mux is complete.
The guard takes none of the renderer's exceptions (thumbnails. allow_private_cidrs): a download is asked for from a public share link by anyone holding it, and a file the asset names on an internal host is left as its URL and named in the notice rather than fetched on their behalf.
Types ¶
type Deps ¶
type Deps struct {
// Routes is the platform's assembled handler: the content route a
// standalone route sits beside, and the reference and vendor routes, are
// read through it.
Routes http.Handler
// External fetches a file on another host; it is the egress-guarded
// client, and is handed a request carrying nothing of the caller's.
External *http.Client
// Limits bounds one export; zero fields take standalone.DefaultLimits.
Limits standalone.Limits
// Limiter admits an export on a public route; nil admits every one.
Limiter interface {
Allow(r *http.Request) bool
RetryAfter() int
}
// Downloads reports whether the signed-in caller's persona includes
// downloading; nil admits every caller.
Downloads func(r *http.Request) bool
// PublicBaseURL is portal.public_base_url: the content route writes a
// declared reference against it when it is set, so it is the origin a
// reference is recognized at.
PublicBaseURL string
// Concurrency is how many exports run at once; zero is
// DefaultConcurrency.
Concurrency int
}
Deps is what the routes export with.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler serves the standalone routes.