spa

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

README

echo-spa-middleware

This echo middleware for use with single page applications (SPA). It resolves the index.html in a static file store with logic to support client side routing and optional sub domain path prefixing for branch builds.

Configuration

This echo middleware has a couple of key configuration options.

  • DomainName - This option enabled the middleware to recognise sub domain request and is used to support branch builds.
  • SubDomainMode - This can be enabled to support rewriting of sub domain to path prefix.

Sub Domains

This middleware supports using the sub domain which prefixes domainName and use it to form a part of the logic to locate the indexFile to be served.

So with a configuration of the following:

e := echo.New()
e.Pre(echomiddleware.AddTrailingSlash()) // required to ensure trailing slash is appended
e.Use(spa.IndexWithConfig(spa.RedirectConfig{
  DomainName: "www.example.com",
  SubDomainMode: true,
}))

branch mode

This middleware supports enabling a branch mode, to support branch builds of an SPA.

At least two DNS records pointing at this service being:

  • www.example.com
  • *.www.example.com
Request URI path served
http://example.com /index.html
http://mybranch_build.example.com /mybranch_build/index.html
http://example.com/someroute /index.html
http://mybranch_build.example.com/someroute /mybranch_build/index.html
http://mybranch_build.example.com/img/logo.png /mybranch_build/img/logo.png

License

This library is released under Apache 2.0 license and is copyright Mark Wolfe.

Documentation

Index

Constants

View Source
const DefaultIndexFilename = "index.html"

DefaultIndexFilename the filename used as the default index

Variables

This section is empty.

Functions

func IndexWithConfig

func IndexWithConfig(cfg IndexConfig) echo.MiddlewareFunc

IndexWithConfig configure the index middleware

Types

type IndexConfig

type IndexConfig struct {
	// Skipper defines a function to skip middleware
	echomiddleware.Skipper

	// This is required to support redirects and branch builds
	DomainName string

	// This can enabled to support serving of branch builds from a folder in a static files store or route
	SubDomainMode bool

	// The name of the file used as the index, defaults to index.html
	IndexFilename string
}

IndexConfig defines the config for the middleware which determines the path to load the SPA index file

Jump to

Keyboard shortcuts

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