spa

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2022 License: MIT Imports: 5 Imported by: 0

README

go-spa

Go Doc Badge Go Report Card Badge

HTTP handler simplifying the process of serving static files for SPAs.

Documentation

Overview

Package spa implements a http.Handler to simplify the process of serving static files for SPAs

Example
http.Handle("/", spa.StaticHandler(http.Dir("/static")))
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func StaticHandler

func StaticHandler(fs http.FileSystem, opts ...Option) http.Handler

StaticHandler returns a http.Handler that serves HTTP requests with the with the contents of the specified file system.

Requests for non-existing files will fallback to serving the content of "/index.html" by default. The fallback path can be changed using Fallback.

Requests for anything other than regular files (directories, symlinks...) also use the fallback logic.

Any request ending in "/index.html" is redirected to the same path, without the final "index.html". This can be disabled using IndexRedirect.

Types

type Option

type Option func(*handler)

Option is used to modify the behavior of StaticHandler.

func Fallback

func Fallback(f string) Option

Fallback is used to modify the fallback path of StaticHandler.

StaticHandler(fs, Fallback("/index.txt"))

func NoIndexRedirect

func NoIndexRedirect() Option

NoIndexRedirect is used to disable the index redirection of StaticHandler.

StaticHandler(fs, NoIndexRedirect())

Jump to

Keyboard shortcuts

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