http

package
v0.2024.4 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package http provides http-specific configuration types and functionality.

Index

Constants

View Source
const (
	HeaderAllowOrigin   = "Access-Control-Allow-Origin"
	HeaderAuthorization = "Authorization"
	HeaderContentType   = "Content-Type"
)

Variables

This section is empty.

Functions

func NewStaticHandler

func NewStaticHandler(staticPath string) http.Handler

func SPAFileServer

func SPAFileServer(root http.FileSystem, handlerSPA SPAHandler) http.Handler

SPAFileServer wraps the http.FileServer checking to see if the url path exists first.

If the file fails to exist it calls the supplied handlerSPA function

The implementation can choose to either modify the request, e.g. change the URL path and return true to have the default FileServer handling to still take place, or return false to stop further processing, for example if you wanted to write a custom response

This code borrows heavily from https://gist.github.com/lummie/91cd1c18b2e32fa9f316862221a6fd5c

Types

type CorsConfig

type CorsConfig struct {
	// DebugMode turns cors debug logging on/off
	DebugMode bool `json:"debugMode,omitempty"`
	// CorsOrigins specifies a list of allowed domains for passing to the CORS handler
	CorsOrigins []string `json:"corsOrigins,omitempty"`
}

type SPAHandler

type SPAHandler = func(w http.ResponseWriter, r *http.Request) (doDefaultFileServe bool)

SPAHandler provides the function signature for passing to the SPAFileServer

type StaticHostingConfig

type StaticHostingConfig struct {
	// the location of the static files
	FilePath string `json:"filePath"`
	// the url path the files should be served on (e.g. "/my-site")
	Path string `json:"path"`
}

Jump to

Keyboard shortcuts

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