Skip to content

plzcloseyoureyes/embedspa

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 

Repository files navigation

embedspa

Embed Single Page Applications like React with Go Embed, Features: Auto Index, ETag support, Strip prefix for specific paths.
Features:
  • Returns index.html contents for unexist routes
  • ETag support for caching
  • Strip prefix for specific paths.

Gin usage example:

package main
import (
    "embed"
    "io/fs"
    "github.com/l10r/embedspa"
    "github.com/gin-gonic/gin"
)

// Embedding the entire dist folder using go's embed:
//go:embed dist
var reactAppEmbed embed.FS

func main() {
    r  := gin.Default()
    embedFS, _  := fs.Sub(reactAppEmbed, "dist")
    spaExample  := embedspa.NewEmbedSPAHandler(embedFS).
        StripPrefixURL("").
        SetIndexPath("index.html")
    r.GET("/*any", gin.WrapF(spaExample.ServeHTTP))
    r.Run()
}

About

Embed Single Page Applications like React with Go Embed, Features: Auto Index, ETag support, Strip prefix for specific paths.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages