Skip to content

Commit

Permalink
feat: v1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
naiba committed Dec 6, 2024
1 parent 5bb013a commit 251bc10
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,20 @@ jobs:

- uses: actions/checkout@v4

- name: clean cache
run: |
rm -rf cmd/dashboard/*-dist
- uses: robinraju/release-downloader@v1
with:
repository: nezhahq/admin-frontend
tag: v1.0.21
tag: v1.1
fileName: dist.zip
latest: true
extract: true

- name: prepare admin-frontend dists
run: |
rm -rf cmd/dashboard/admin-dist
mv dist cmd/dashboard/admin-dist
- uses: robinraju/release-downloader@v1
Expand All @@ -52,20 +55,18 @@ jobs:

- name: prepare admin-frontend dists
run: |
rm -rf cmd/dashboard/user-dist
mv dist cmd/dashboard/user-dist
- uses: robinraju/release-downloader@v1
with:
repository: hi2shark/nazhua
tag: v0.4.2
tag: v0.4.3
fileName: dist.zip
latest: true
extract: true

- name: prepare nazhua-frontend dists
run: |
rm -rf cmd/dashboard/nazhua-dist
mv dist cmd/dashboard/nazhua-dist
- name: Fetch IPInfo GeoIP Database
Expand Down
18 changes: 9 additions & 9 deletions cmd/dashboard/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/nezhahq/nezha/service/singleton"
)

func ServeWeb(adminFrontend, userFrontend fs.FS) http.Handler {
func ServeWeb(frontendDist fs.FS) http.Handler {
gin.SetMode(gin.ReleaseMode)
r := gin.Default()

Expand All @@ -40,12 +40,12 @@ func ServeWeb(adminFrontend, userFrontend fs.FS) http.Handler {
r.Use(waf.Waf)
r.Use(recordPath)

routers(r, adminFrontend, userFrontend)
routers(r, frontendDist)

return r
}

func routers(r *gin.Engine, adminFrontend, userFrontend fs.FS) {
func routers(r *gin.Engine, frontendDist fs.FS) {
authMiddleware, err := jwt.New(initParams())
if err != nil {
log.Fatal("JWT Error:" + err.Error())
Expand Down Expand Up @@ -133,7 +133,7 @@ func routers(r *gin.Engine, adminFrontend, userFrontend fs.FS) {

auth.PATCH("/setting", commonHandler(updateConfig))

r.NoRoute(fallbackToFrontend(adminFrontend, userFrontend))
r.NoRoute(fallbackToFrontend(frontendDist))
}

func recordPath(c *gin.Context) {
Expand Down Expand Up @@ -212,7 +212,7 @@ func commonHandler[T any](handler handlerFunc[T]) func(*gin.Context) {
}
}

func fallbackToFrontend(adminFrontend, userFrontend fs.FS) func(*gin.Context) {
func fallbackToFrontend(frontendDist fs.FS) func(*gin.Context) {
checkLocalFileOrFs := func(c *gin.Context, fs fs.FS, path string) bool {
if _, err := os.Stat(path); err == nil {
c.File(path)
Expand Down Expand Up @@ -241,19 +241,19 @@ func fallbackToFrontend(adminFrontend, userFrontend fs.FS) func(*gin.Context) {
if strings.HasPrefix(c.Request.URL.Path, "/dashboard") {
stripPath := strings.TrimPrefix(c.Request.URL.Path, "/dashboard")
localFilePath := path.Join("admin-dist", stripPath)
if checkLocalFileOrFs(c, adminFrontend, localFilePath) {
if checkLocalFileOrFs(c, frontendDist, localFilePath) {
return
}
if !checkLocalFileOrFs(c, adminFrontend, "admin-dist/index.html") {
if !checkLocalFileOrFs(c, frontendDist, "admin-dist/index.html") {
c.JSON(http.StatusOK, newErrorResponse(errors.New("404 Not Found")))
}
return
}
localFilePath := path.Join(singleton.Conf.UserTemplate, c.Request.URL.Path)
if checkLocalFileOrFs(c, userFrontend, localFilePath) {
if checkLocalFileOrFs(c, frontendDist, localFilePath) {
return
}
if !checkLocalFileOrFs(c, userFrontend, singleton.Conf.UserTemplate+"/index.html") {
if !checkLocalFileOrFs(c, frontendDist, singleton.Conf.UserTemplate+"/index.html") {
c.JSON(http.StatusOK, newErrorResponse(errors.New("404 Not Found")))
}
}
Expand Down
8 changes: 3 additions & 5 deletions cmd/dashboard/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ type DashboardCliParam struct {

var (
dashboardCliParam DashboardCliParam
//go:embed admin-dist
adminFrontend embed.FS
//go:embed user-dist
userFrontend embed.FS
//go:embed *-dist
frontendDist embed.FS
)

func initSystem() {
Expand Down Expand Up @@ -125,7 +123,7 @@ func main() {
singleton.NewServiceSentinel(serviceSentinelDispatchBus)

grpcHandler := rpc.ServeRPC()
httpHandler := controller.ServeWeb(adminFrontend, userFrontend)
httpHandler := controller.ServeWeb(frontendDist)
controller.InitUpgrader()

muxHandler := newHTTPandGRPCMux(httpHandler, grpcHandler)
Expand Down

0 comments on commit 251bc10

Please sign in to comment.