mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: update dockerfile
This commit is contained in:
@ -1,11 +1,10 @@
|
||||
package frontend
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
@ -20,12 +19,6 @@ import (
|
||||
"github.com/usememos/memos/store"
|
||||
)
|
||||
|
||||
//go:embed dist
|
||||
var embeddedFiles embed.FS
|
||||
|
||||
//go:embed dist/index.html
|
||||
var rawIndexHTML string
|
||||
|
||||
type FrontendService struct {
|
||||
Profile *profile.Profile
|
||||
Store *store.Store
|
||||
@ -42,32 +35,18 @@ func (s *FrontendService) Serve(e *echo.Echo) {
|
||||
// Use echo static middleware to serve the built dist folder.
|
||||
// refer: https://github.com/labstack/echo/blob/master/middleware/static.go
|
||||
e.Use(middleware.StaticWithConfig(middleware.StaticConfig{
|
||||
Skipper: defaultAPIRequestSkipper,
|
||||
HTML5: true,
|
||||
Filesystem: getFileSystem("dist"),
|
||||
}))
|
||||
|
||||
assetsGroup := e.Group("assets")
|
||||
assetsGroup.Use(middleware.GzipWithConfig(middleware.GzipConfig{
|
||||
Root: "dist",
|
||||
Skipper: defaultAPIRequestSkipper,
|
||||
Level: 5,
|
||||
}))
|
||||
assetsGroup.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
c.Response().Header().Set(echo.HeaderCacheControl, "max-age=31536000, immutable")
|
||||
return next(c)
|
||||
}
|
||||
})
|
||||
assetsGroup.Use(middleware.StaticWithConfig(middleware.StaticConfig{
|
||||
Skipper: defaultAPIRequestSkipper,
|
||||
HTML5: true,
|
||||
Filesystem: getFileSystem("dist/assets"),
|
||||
HTML5: true,
|
||||
}))
|
||||
|
||||
s.registerRoutes(e)
|
||||
}
|
||||
|
||||
func (s *FrontendService) registerRoutes(e *echo.Echo) {
|
||||
rawIndexHTMLBytes, _ := os.ReadFile("dist/index.html")
|
||||
rawIndexHTML := string(rawIndexHTMLBytes)
|
||||
|
||||
e.GET("/robots.txt", func(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
instanceURLSetting, err := s.Store.GetSystemSetting(ctx, &store.FindSystemSetting{
|
||||
@ -194,14 +173,6 @@ func generateMemoMetadata(memo *store.Memo, creator *store.User) string {
|
||||
return strings.Join(metadataList, "\n")
|
||||
}
|
||||
|
||||
func getFileSystem(path string) http.FileSystem {
|
||||
fs, err := fs.Sub(embeddedFiles, path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return http.FS(fs)
|
||||
}
|
||||
|
||||
func defaultAPIRequestSkipper(c echo.Context) bool {
|
||||
path := c.Request().URL.Path
|
||||
return util.HasPrefixes(path, "/api", "/memos.api.v2")
|
||||
|
Reference in New Issue
Block a user