spa

package module
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: May 29, 2024 License: BSD-3-Clause Imports: 6 Imported by: 1

README

Single Page App File Service

Often Single Page Apps (SPA) that keep history use the URl path to track the location in the application. When people refresh a page or use a bookmark in the browser this leads to paths like https://example.com/login that should serve the index.html page but instead result in 404 errors.

This middleware allows for a list of different paths that can be remapped to index.html or other files. Files that are legitimately missing will still be returned as 404 errors - but items in the list will remapped to a specified file (usually index.html).

example

package main

import (
	"os"

	"github.com/gin-gonic/gin"
	spa "github.com/pschlump/gin-spa"
)

func main() {
	r := gin.Default()
	pathsToRemap = map[string]string{
		"/login": "/index.html",
		"/logout": "/index.html",
	}
	r.Use(spa.StaticServeMiddleware("/", "./build", pathsToRemap, os.Stderr)) // your build of React or other SPA
	r.Run()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InSpaList

func InSpaList(s string, spa SPAList) (to string, found bool)

func ResetLogFile added in v1.0.9

func ResetLogFile(newFp io.WriteCloser)

func ResetLogFile(newFp *os.File) {

func StaticServeMiddleware

func StaticServeMiddleware(urlPrefix, spaDirectory string, spa map[string]string, logFile io.WriteCloser) gin.HandlerFunc

func StaticServeMiddleware(urlPrefix, spaDirectory string, spa map[string]string, logFile *os.File) gin.HandlerFunc {

Types

type SPAList

type SPAList struct {
	FromTo map[string]string
	// contains filtered or unexported fields
}

Directories

Path Synopsis
example
spa-server Module

Jump to

Keyboard shortcuts

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