forked from 0x2E/fusion
refactor: embed pages
This commit is contained in:
parent
2f1bf7ca4f
commit
a60e89129d
2 changed files with 22 additions and 7 deletions
10
api/api.go
10
api/api.go
|
@ -9,6 +9,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/0x2e/fusion/conf"
|
||||
"github.com/0x2e/fusion/frontend"
|
||||
"github.com/0x2e/fusion/pkg/errorx"
|
||||
"github.com/0x2e/fusion/repo"
|
||||
"github.com/0x2e/fusion/server"
|
||||
|
@ -55,16 +56,11 @@ func Run() {
|
|||
return nil
|
||||
},
|
||||
}))
|
||||
r.Use(session.Middleware(sessions.NewCookieStore([]byte("secret"))))
|
||||
r.Use(middleware.StaticWithConfig(middleware.StaticConfig{
|
||||
Root: "./frontend",
|
||||
Index: "index.html",
|
||||
HTML5: true,
|
||||
Browse: false,
|
||||
}))
|
||||
r.Use(session.Middleware(sessions.NewCookieStore([]byte("fusion"))))
|
||||
r.Pre(middleware.RemoveTrailingSlash())
|
||||
|
||||
r.StaticFS("/*", frontend.Content)
|
||||
|
||||
loginAPI := Session{}
|
||||
r.POST("/api/sessions", loginAPI.Create)
|
||||
|
||||
|
|
19
frontend/embed.go
Normal file
19
frontend/embed.go
Normal file
|
@ -0,0 +1,19 @@
|
|||
package frontend
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"io/fs"
|
||||
)
|
||||
|
||||
//go:embed all:build
|
||||
var build embed.FS
|
||||
|
||||
var Content fs.FS
|
||||
|
||||
func init() {
|
||||
sub, err := fs.Sub(build, "build")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
Content = sub
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue