fix(embed_fs): enable embed fs for prod
This commit is contained in:
parent
56505dacdd
commit
d7263cc3c8
3 changed files with 19 additions and 8 deletions
|
@ -82,7 +82,10 @@ func (h *MultiUsersSvc) APIAccessControl() gin.HandlerFunc {
|
|||
return
|
||||
} else if accessPath == "/" || // TODO: temporarily allow accessing static resources
|
||||
accessPath == "/favicon.ico" ||
|
||||
strings.HasPrefix(accessPath, "/static") {
|
||||
strings.HasPrefix(accessPath, "/css") ||
|
||||
strings.HasPrefix(accessPath, "/font") ||
|
||||
strings.HasPrefix(accessPath, "/img") ||
|
||||
strings.HasPrefix(accessPath, "/js") {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
|
|
|
@ -111,7 +111,7 @@ func DefaultConfigStruct() *Config {
|
|||
ReadTimeout: 2000,
|
||||
WriteTimeout: 1000 * 3600 * 24, // 1 day
|
||||
MaxHeaderBytes: 512,
|
||||
PublicPath: "public",
|
||||
PublicPath: "static/public",
|
||||
},
|
||||
Workers: &WorkerPoolCfg{
|
||||
QueueSize: 1024,
|
||||
|
|
|
@ -39,6 +39,7 @@ import (
|
|||
"github.com/ihexxa/quickshare/src/kvstore"
|
||||
"github.com/ihexxa/quickshare/src/kvstore/boltdbpvd"
|
||||
"github.com/ihexxa/quickshare/src/worker/localworker"
|
||||
qsstatic "github.com/ihexxa/quickshare/static"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
|
@ -251,16 +252,23 @@ func initHandlers(router *gin.Engine, cfg gocfg.ICfg, deps *depidx.Deps) (*gin.E
|
|||
return nil, fmt.Errorf("new setting service error: %w", err)
|
||||
}
|
||||
|
||||
// middleware
|
||||
router.Use(userHdrs.AuthN())
|
||||
router.Use(userHdrs.APIAccessControl())
|
||||
|
||||
publicPath, ok := cfg.String("Server.PublicPath")
|
||||
if !ok || publicPath == "" {
|
||||
return nil, errors.New("publicPath not found or empty")
|
||||
}
|
||||
|
||||
// middleware
|
||||
router.Use(userHdrs.AuthN())
|
||||
router.Use(userHdrs.APIAccessControl())
|
||||
// tmp static server
|
||||
router.Use(static.Serve("/", static.LocalFile(publicPath, false)))
|
||||
if cfg.BoolOr("Server.Debug", false) {
|
||||
router.Use(static.Serve("/", static.LocalFile(publicPath, false)))
|
||||
} else {
|
||||
esFS, err := qsstatic.NewEmbedStaticFS()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
router.Use(static.Serve("/", esFS))
|
||||
}
|
||||
|
||||
// handler
|
||||
v1 := router.Group("/v1")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue