feat: v1.1
This commit is contained in:
parent
5bb013af04
commit
251bc10af9
11
.github/workflows/release.yml
vendored
11
.github/workflows/release.yml
vendored
@ -29,17 +29,20 @@ jobs:
|
|||||||
|
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: clean cache
|
||||||
|
run: |
|
||||||
|
rm -rf cmd/dashboard/*-dist
|
||||||
|
|
||||||
- uses: robinraju/release-downloader@v1
|
- uses: robinraju/release-downloader@v1
|
||||||
with:
|
with:
|
||||||
repository: nezhahq/admin-frontend
|
repository: nezhahq/admin-frontend
|
||||||
tag: v1.0.21
|
tag: v1.1
|
||||||
fileName: dist.zip
|
fileName: dist.zip
|
||||||
latest: true
|
latest: true
|
||||||
extract: true
|
extract: true
|
||||||
|
|
||||||
- name: prepare admin-frontend dists
|
- name: prepare admin-frontend dists
|
||||||
run: |
|
run: |
|
||||||
rm -rf cmd/dashboard/admin-dist
|
|
||||||
mv dist cmd/dashboard/admin-dist
|
mv dist cmd/dashboard/admin-dist
|
||||||
|
|
||||||
- uses: robinraju/release-downloader@v1
|
- uses: robinraju/release-downloader@v1
|
||||||
@ -52,20 +55,18 @@ jobs:
|
|||||||
|
|
||||||
- name: prepare admin-frontend dists
|
- name: prepare admin-frontend dists
|
||||||
run: |
|
run: |
|
||||||
rm -rf cmd/dashboard/user-dist
|
|
||||||
mv dist cmd/dashboard/user-dist
|
mv dist cmd/dashboard/user-dist
|
||||||
|
|
||||||
- uses: robinraju/release-downloader@v1
|
- uses: robinraju/release-downloader@v1
|
||||||
with:
|
with:
|
||||||
repository: hi2shark/nazhua
|
repository: hi2shark/nazhua
|
||||||
tag: v0.4.2
|
tag: v0.4.3
|
||||||
fileName: dist.zip
|
fileName: dist.zip
|
||||||
latest: true
|
latest: true
|
||||||
extract: true
|
extract: true
|
||||||
|
|
||||||
- name: prepare nazhua-frontend dists
|
- name: prepare nazhua-frontend dists
|
||||||
run: |
|
run: |
|
||||||
rm -rf cmd/dashboard/nazhua-dist
|
|
||||||
mv dist cmd/dashboard/nazhua-dist
|
mv dist cmd/dashboard/nazhua-dist
|
||||||
|
|
||||||
- name: Fetch IPInfo GeoIP Database
|
- name: Fetch IPInfo GeoIP Database
|
||||||
|
@ -23,7 +23,7 @@ import (
|
|||||||
"github.com/nezhahq/nezha/service/singleton"
|
"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)
|
gin.SetMode(gin.ReleaseMode)
|
||||||
r := gin.Default()
|
r := gin.Default()
|
||||||
|
|
||||||
@ -40,12 +40,12 @@ func ServeWeb(adminFrontend, userFrontend fs.FS) http.Handler {
|
|||||||
r.Use(waf.Waf)
|
r.Use(waf.Waf)
|
||||||
r.Use(recordPath)
|
r.Use(recordPath)
|
||||||
|
|
||||||
routers(r, adminFrontend, userFrontend)
|
routers(r, frontendDist)
|
||||||
|
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func routers(r *gin.Engine, adminFrontend, userFrontend fs.FS) {
|
func routers(r *gin.Engine, frontendDist fs.FS) {
|
||||||
authMiddleware, err := jwt.New(initParams())
|
authMiddleware, err := jwt.New(initParams())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("JWT Error:" + err.Error())
|
log.Fatal("JWT Error:" + err.Error())
|
||||||
@ -133,7 +133,7 @@ func routers(r *gin.Engine, adminFrontend, userFrontend fs.FS) {
|
|||||||
|
|
||||||
auth.PATCH("/setting", commonHandler(updateConfig))
|
auth.PATCH("/setting", commonHandler(updateConfig))
|
||||||
|
|
||||||
r.NoRoute(fallbackToFrontend(adminFrontend, userFrontend))
|
r.NoRoute(fallbackToFrontend(frontendDist))
|
||||||
}
|
}
|
||||||
|
|
||||||
func recordPath(c *gin.Context) {
|
func recordPath(c *gin.Context) {
|
||||||
@ -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 {
|
checkLocalFileOrFs := func(c *gin.Context, fs fs.FS, path string) bool {
|
||||||
if _, err := os.Stat(path); err == nil {
|
if _, err := os.Stat(path); err == nil {
|
||||||
c.File(path)
|
c.File(path)
|
||||||
@ -241,19 +241,19 @@ func fallbackToFrontend(adminFrontend, userFrontend fs.FS) func(*gin.Context) {
|
|||||||
if strings.HasPrefix(c.Request.URL.Path, "/dashboard") {
|
if strings.HasPrefix(c.Request.URL.Path, "/dashboard") {
|
||||||
stripPath := strings.TrimPrefix(c.Request.URL.Path, "/dashboard")
|
stripPath := strings.TrimPrefix(c.Request.URL.Path, "/dashboard")
|
||||||
localFilePath := path.Join("admin-dist", stripPath)
|
localFilePath := path.Join("admin-dist", stripPath)
|
||||||
if checkLocalFileOrFs(c, adminFrontend, localFilePath) {
|
if checkLocalFileOrFs(c, frontendDist, localFilePath) {
|
||||||
return
|
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")))
|
c.JSON(http.StatusOK, newErrorResponse(errors.New("404 Not Found")))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
localFilePath := path.Join(singleton.Conf.UserTemplate, c.Request.URL.Path)
|
localFilePath := path.Join(singleton.Conf.UserTemplate, c.Request.URL.Path)
|
||||||
if checkLocalFileOrFs(c, userFrontend, localFilePath) {
|
if checkLocalFileOrFs(c, frontendDist, localFilePath) {
|
||||||
return
|
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")))
|
c.JSON(http.StatusOK, newErrorResponse(errors.New("404 Not Found")))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,10 +34,8 @@ type DashboardCliParam struct {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
dashboardCliParam DashboardCliParam
|
dashboardCliParam DashboardCliParam
|
||||||
//go:embed admin-dist
|
//go:embed *-dist
|
||||||
adminFrontend embed.FS
|
frontendDist embed.FS
|
||||||
//go:embed user-dist
|
|
||||||
userFrontend embed.FS
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func initSystem() {
|
func initSystem() {
|
||||||
@ -125,7 +123,7 @@ func main() {
|
|||||||
singleton.NewServiceSentinel(serviceSentinelDispatchBus)
|
singleton.NewServiceSentinel(serviceSentinelDispatchBus)
|
||||||
|
|
||||||
grpcHandler := rpc.ServeRPC()
|
grpcHandler := rpc.ServeRPC()
|
||||||
httpHandler := controller.ServeWeb(adminFrontend, userFrontend)
|
httpHandler := controller.ServeWeb(frontendDist)
|
||||||
controller.InitUpgrader()
|
controller.InitUpgrader()
|
||||||
|
|
||||||
muxHandler := newHTTPandGRPCMux(httpHandler, grpcHandler)
|
muxHandler := newHTTPandGRPCMux(httpHandler, grpcHandler)
|
||||||
|
Loading…
Reference in New Issue
Block a user