standalonehttp

package
v1.164.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

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

View Source
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

View Source
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

func MountFor(mux *http.ServeMux, p *platform.Platform)

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.

func New

func New(d Deps) *Handler

New returns the handler.

func (*Handler) Mount

func (h *Handler) Mount(mux *http.ServeMux)

Mount registers every standalone route on mux.

type Refusal

type Refusal struct {
	// Error is platform_data or build_failed.
	Error string `json:"error" example:"platform_data"`
	// Reasons are the sentences the portal shows.
	Reasons []string `json:"reasons"`
}

Refusal is a 409 or 422 answer's body.

type Route

type Route struct {
	Pattern string
	Content string
	// Public is a route a caller reaches with no session, limited per client:
	// an export fetches files on other hosts on the caller's behalf.
	Public bool
}

Route is one standalone route and the content route beside it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL