mirror of
https://github.com/usememos/memos.git
synced 2025-02-19 12:50:41 +01:00
chore: use echo static middleware to serve dist
This commit is contained in:
parent
6053df050c
commit
1b50ab5dca
19
.gitignore
vendored
19
.gitignore
vendored
@ -1,29 +1,10 @@
|
|||||||
# Binaries for programs and plugins
|
|
||||||
*.exe
|
|
||||||
*.exe~
|
|
||||||
*.dll
|
|
||||||
*.so
|
|
||||||
*.dylib
|
|
||||||
|
|
||||||
# Test binary, built with `go test -c`
|
|
||||||
*.test
|
|
||||||
|
|
||||||
# Temp output
|
|
||||||
*.out
|
|
||||||
*.log
|
|
||||||
tmp
|
|
||||||
|
|
||||||
# Air (hot reload) generated
|
# Air (hot reload) generated
|
||||||
.air
|
.air
|
||||||
|
|
||||||
# Frontend asset
|
# Frontend asset
|
||||||
web/dist
|
web/dist
|
||||||
|
|
||||||
# Dev database
|
|
||||||
data
|
|
||||||
|
|
||||||
# build folder
|
# build folder
|
||||||
build
|
|
||||||
memos-build
|
memos-build
|
||||||
|
|
||||||
.DS_Store
|
.DS_Store
|
@ -6,14 +6,12 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
|
"github.com/labstack/echo/v4/middleware"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed dist
|
//go:embed dist
|
||||||
var embeddedFiles embed.FS
|
var embeddedFiles embed.FS
|
||||||
|
|
||||||
//go:embed dist/index.html
|
|
||||||
var indexContent string
|
|
||||||
|
|
||||||
func getFileSystem() http.FileSystem {
|
func getFileSystem() http.FileSystem {
|
||||||
fs, err := fs.Sub(embeddedFiles, "dist")
|
fs, err := fs.Sub(embeddedFiles, "dist")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -24,14 +22,8 @@ func getFileSystem() http.FileSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func embedFrontend(e *echo.Echo) {
|
func embedFrontend(e *echo.Echo) {
|
||||||
// Catch-all route to return index.html, this is to prevent 404 when accessing non-root url.
|
e.Use(middleware.StaticWithConfig(middleware.StaticConfig{
|
||||||
// See https://stackoverflow.com/questions/27928372/react-router-urls-dont-work-when-refreshing-or-writing-manually
|
HTML5: true,
|
||||||
e.GET("/*", func(c echo.Context) error {
|
Filesystem: getFileSystem(),
|
||||||
return c.HTML(http.StatusOK, indexContent)
|
}))
|
||||||
})
|
|
||||||
|
|
||||||
assetHandler := http.FileServer(getFileSystem())
|
|
||||||
e.GET("/assets/*", echo.WrapHandler(assetHandler))
|
|
||||||
e.GET("/icons/*", echo.WrapHandler(assetHandler))
|
|
||||||
e.GET("/favicon.svg", echo.WrapHandler(assetHandler))
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user