Documentation
¶
Overview ¶
Package staticroutes parses and evaluates the in-repo routing rules of a static site: Netlify style _redirects and _headers files, the app.yaml routes and headers blocks, and the SPA, clean URL and 404 options.
Index ¶
- Constants
- func ParseHeaders(src string, l Limits) ([]HeaderBlock, []Problem)
- func ParseRedirects(src string, l Limits) ([]Rule, []Problem)
- func SidecarPath(rootDir string) string
- func ValidateHeaderBlock(b *HeaderBlock, l Limits) error
- func ValidateRule(r *Rule, l Limits) error
- func WriteSidecar(rootDir string, rs *Ruleset) error
- type Decision
- type HeaderBlock
- type HeaderKV
- type Input
- type Limits
- type Options
- type Problem
- type QueryMatch
- type Request
- type Rule
- type Ruleset
- type StatFS
Constants ¶
const ( EnvMaxRules = spec.EnvStaticMaxRules EnvMaxHeaderRules = spec.EnvStaticMaxHeaderBlocks EnvMaxFileBytes = "APP_STATIC_ROUTES_MAX_FILE_BYTES" EnvMaxValueLen = "APP_STATIC_ROUTES_MAX_VALUE_LEN" )
Environment variables that tune the caps below. Every one is optional.
const ( KindServe = "serve" KindRedirect = "redirect" KindNotFound = "not_found" )
Decision kinds.
const ( SourceRedirects = spec.StaticSourceRedirects SourceHeaders = spec.StaticSourceHeaders SourceSpec = spec.StaticSourceSpec )
Rule and header sources, shown next to each parsed rule.
const ( SeverityError = spec.StaticSeverityError SeverityWarning = spec.StaticSeverityWarning )
Problem severities.
const ( SlashOff = spec.StaticSlashOff SlashAdd = spec.StaticSlashAdd SlashRemove = spec.StaticSlashRemove )
Trailing slash modes for Options.TrailingSlash.
const SidecarSuffix = spec.StaticSidecarSuffix
SidecarSuffix names the compiled rules file stored beside a published tree.
Variables ¶
This section is empty.
Functions ¶
func ParseHeaders ¶
func ParseHeaders(src string, l Limits) ([]HeaderBlock, []Problem)
ParseHeaders parses Netlify _headers syntax; bad lines are reported, never applied.
func ParseRedirects ¶
ParseRedirects parses Netlify _redirects syntax; bad lines are reported, never applied.
func SidecarPath ¶
SidecarPath is where the ruleset of the tree at rootDir is stored.
func ValidateHeaderBlock ¶
func ValidateHeaderBlock(b *HeaderBlock, l Limits) error
ValidateHeaderBlock checks a block built from app.yaml and prepares it.
func ValidateRule ¶
ValidateRule checks a rule and prepares its matcher. It is the single gate for file rules and app.yaml rules alike.
func WriteSidecar ¶
WriteSidecar stores rs beside the tree at rootDir, replacing any earlier one.
Types ¶
type Decision ¶
type Decision struct {
Kind string `json:"kind"`
Status int `json:"status"`
Location string `json:"location,omitempty"`
File string `json:"file,omitempty"`
Rule string `json:"rule,omitempty"`
Headers []HeaderKV `json:"headers"`
Remove []string `json:"remove_headers"`
Trace []string `json:"trace"`
}
Decision is the outcome for one request. File is relative to the site root. Trace lists, in order, every step considered.
type HeaderBlock ¶
type HeaderBlock = spec.StaticHeaderBlock
HeaderBlock applies header changes to matching paths.
type Limits ¶
type Limits = spec.StaticLimits
Limits caps the size of a site's routing rules.
func DefaultLimits ¶
func DefaultLimits() Limits
DefaultLimits are the caps used when no environment override is set.
type Problem ¶
type Problem = spec.StaticProblem
Problem is one validation finding. Line is 0 for spec rules.
type Request ¶
Request is the part of an HTTP request resolution looks at. Path is the decoded URL path.
type Ruleset ¶
type Ruleset struct {
spec.StaticRuleset
}
Ruleset is everything compiled for one deploy; Resolve evaluates it.
func LoadSidecar ¶
LoadSidecar reads the ruleset of the tree at rootDir; none yields nil without an error.