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 ¶
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())