mirror of
https://github.com/WJQSERVER-STUDIO/ghproxy.git
synced 2026-02-03 08:11:11 +08:00
optimize frontend load
This commit is contained in:
parent
8e5cfd1fac
commit
7e5092179e
1 changed files with 20 additions and 7 deletions
27
main.go
27
main.go
|
|
@ -146,7 +146,7 @@ func InitReq(cfg *config.Config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadEmbeddedPages 加载嵌入式页面资源
|
// loadEmbeddedPages 加载嵌入式页面资源
|
||||||
func loadEmbeddedPages(cfg *config.Config) (fs.FS, error) {
|
func loadEmbeddedPages(cfg *config.Config) (fs.FS, fs.FS, error) {
|
||||||
var pages fs.FS
|
var pages fs.FS
|
||||||
var err error
|
var err error
|
||||||
switch cfg.Pages.Theme {
|
switch cfg.Pages.Theme {
|
||||||
|
|
@ -168,9 +168,15 @@ func loadEmbeddedPages(cfg *config.Config) (fs.FS, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to load embedded pages: %w", err)
|
return nil, nil, fmt.Errorf("failed to load embedded pages: %w", err)
|
||||||
}
|
}
|
||||||
return pages, nil
|
|
||||||
|
var assets fs.FS
|
||||||
|
assets, err = fs.Sub(pagesFS, "pages/assets")
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, fmt.Errorf("failed to load embedded assets: %w", err)
|
||||||
|
}
|
||||||
|
return pages, assets, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// setupPages 设置页面路由
|
// setupPages 设置页面路由
|
||||||
|
|
@ -178,7 +184,7 @@ func setupPages(cfg *config.Config, router *gin.Engine) {
|
||||||
switch cfg.Pages.Mode {
|
switch cfg.Pages.Mode {
|
||||||
case "internal":
|
case "internal":
|
||||||
// 加载嵌入式资源
|
// 加载嵌入式资源
|
||||||
pages, err := loadEmbeddedPages(cfg)
|
pages, assets, err := loadEmbeddedPages(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logError("Failed when processing internal pages: %s", err)
|
logError("Failed when processing internal pages: %s", err)
|
||||||
return
|
return
|
||||||
|
|
@ -189,7 +195,8 @@ func setupPages(cfg *config.Config, router *gin.Engine) {
|
||||||
router.GET("/favicon.ico", gin.WrapH(http.FileServer(http.FS(pages))))
|
router.GET("/favicon.ico", gin.WrapH(http.FileServer(http.FS(pages))))
|
||||||
router.GET("/script.js", gin.WrapH(http.FileServer(http.FS(pages))))
|
router.GET("/script.js", gin.WrapH(http.FileServer(http.FS(pages))))
|
||||||
router.GET("/style.css", gin.WrapH(http.FileServer(http.FS(pages))))
|
router.GET("/style.css", gin.WrapH(http.FileServer(http.FS(pages))))
|
||||||
//router.GET("/bootstrap.min.css", gin.WrapH(http.FileServer(http.FS(pages))))
|
router.GET("/bootstrap.min.css", gin.WrapH(http.FileServer(http.FS(assets))))
|
||||||
|
router.GET("/bootstrap.bundle.min.js", gin.WrapH(http.FileServer(http.FS(assets))))
|
||||||
|
|
||||||
case "external":
|
case "external":
|
||||||
// 设置外部资源路径
|
// 设置外部资源路径
|
||||||
|
|
@ -197,7 +204,8 @@ func setupPages(cfg *config.Config, router *gin.Engine) {
|
||||||
faviconPath := fmt.Sprintf("%s/favicon.ico", cfg.Pages.StaticDir)
|
faviconPath := fmt.Sprintf("%s/favicon.ico", cfg.Pages.StaticDir)
|
||||||
javascriptsPath := fmt.Sprintf("%s/script.js", cfg.Pages.StaticDir)
|
javascriptsPath := fmt.Sprintf("%s/script.js", cfg.Pages.StaticDir)
|
||||||
stylesheetsPath := fmt.Sprintf("%s/style.css", cfg.Pages.StaticDir)
|
stylesheetsPath := fmt.Sprintf("%s/style.css", cfg.Pages.StaticDir)
|
||||||
//bootstrapPath := fmt.Sprintf("%s/bootstrap.min.css", cfg.Pages.StaticDir)
|
bootstrapPath := fmt.Sprintf("%s/bootstrap.min.css", cfg.Pages.StaticDir)
|
||||||
|
bootstrapBundlePath := fmt.Sprintf("%s/bootstrap.bundle.min.js", cfg.Pages.StaticDir)
|
||||||
|
|
||||||
// 设置外部资源路由
|
// 设置外部资源路由
|
||||||
router.GET("/", func(c *gin.Context) {
|
router.GET("/", func(c *gin.Context) {
|
||||||
|
|
@ -207,6 +215,9 @@ func setupPages(cfg *config.Config, router *gin.Engine) {
|
||||||
router.StaticFile("/favicon.ico", faviconPath)
|
router.StaticFile("/favicon.ico", faviconPath)
|
||||||
router.StaticFile("/script.js", javascriptsPath)
|
router.StaticFile("/script.js", javascriptsPath)
|
||||||
router.StaticFile("/style.css", stylesheetsPath)
|
router.StaticFile("/style.css", stylesheetsPath)
|
||||||
|
router.StaticFile("/bootstrap.min.css", bootstrapPath)
|
||||||
|
router.StaticFile("/bootstrap.bundle.min.js", bootstrapBundlePath)
|
||||||
|
|
||||||
//router.StaticFile("/bootstrap.min.css", bootstrapPath)
|
//router.StaticFile("/bootstrap.min.css", bootstrapPath)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
@ -214,7 +225,7 @@ func setupPages(cfg *config.Config, router *gin.Engine) {
|
||||||
logWarning("Invalid Pages Mode: %s, using default embedded theme", cfg.Pages.Mode)
|
logWarning("Invalid Pages Mode: %s, using default embedded theme", cfg.Pages.Mode)
|
||||||
|
|
||||||
// 加载嵌入式资源
|
// 加载嵌入式资源
|
||||||
pages, err := loadEmbeddedPages(cfg)
|
pages, assets, err := loadEmbeddedPages(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logError("Failed when processing pages: %s", err)
|
logError("Failed when processing pages: %s", err)
|
||||||
return
|
return
|
||||||
|
|
@ -224,6 +235,8 @@ func setupPages(cfg *config.Config, router *gin.Engine) {
|
||||||
router.GET("/favicon.ico", gin.WrapH(http.FileServer(http.FS(pages))))
|
router.GET("/favicon.ico", gin.WrapH(http.FileServer(http.FS(pages))))
|
||||||
router.GET("/script.js", gin.WrapH(http.FileServer(http.FS(pages))))
|
router.GET("/script.js", gin.WrapH(http.FileServer(http.FS(pages))))
|
||||||
router.GET("/style.css", gin.WrapH(http.FileServer(http.FS(pages))))
|
router.GET("/style.css", gin.WrapH(http.FileServer(http.FS(pages))))
|
||||||
|
router.GET("/bootstrap.min.css", gin.WrapH(http.FileServer(http.FS(assets))))
|
||||||
|
router.GET("/bootstrap.bundle.min.js", gin.WrapH(http.FileServer(http.FS(assets))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue