staticfiles

package
v0.0.0-...-e05d22d Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CachedStaticFileServer

type CachedStaticFileServer struct {
	// contains filtered or unexported fields
}

CachedStaticFileServer gzips static files so that we don't pay that compression price for every request. Nginx can do this transparently, and we do use that functionality for API requests. Nginx also has a proxy cache that can supposedly be used for gzipped content, but in my experiments I was unable to get nginx to cache the gzipped content. I presume that Nginx is only built to cache gzipped content from files on disk, not from files that come from a proxy.

func NewCachedStaticFileServer

func NewCachedStaticFileServer(fsys fs.FS, fsRootDir string, apiRoutes []string, log logs.Log, immutableFilesystem bool, indexIntercept http.HandlerFunc) (*CachedStaticFileServer, error)

absRoot is the root content path. apiRoutes are special routes such as /api, which should not serve up your index.html, but return a 404 instead. The assumption is that your SPA's router module figures out which page to show based on the URL, but from the server's perspective, everything except for apiRoutes serves up index.html indexIntercept can be used to modify a request/response to index.html.

func (*CachedStaticFileServer) ServeFile

func (s *CachedStaticFileServer) ServeFile(w http.ResponseWriter, r *http.Request, relPath string, maxAgeSeconds int)

func (*CachedStaticFileServer) ServeHTTP

This is our static files handler, which gets hit if none of our other routes match. Most routes match API entrypoints.

Jump to

Keyboard shortcuts

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