patch(version): Implemented version reporting for the app
Some checks failed
Build and Publish Docker Image / deploy (push) Has been cancelled
Some checks failed
Build and Publish Docker Image / deploy (push) Has been cancelled
This commit is contained in:
@@ -24,6 +24,7 @@ func (app *App) handleIndex(ctx *gin.Context) {
|
||||
"UploadsEnabled": app.config.GuestUploadsEnabled && app.config.APIEnabled,
|
||||
"MaxFileSizeBytes": app.config.GlobalMaxFileSizeBytes,
|
||||
"MaxBoxSizeBytes": app.config.GlobalMaxBoxSizeBytes,
|
||||
"AppVersion": app.appVersion,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,9 @@ package server
|
||||
import (
|
||||
"encoding/json"
|
||||
"html/template"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gin-contrib/gzip"
|
||||
@@ -23,6 +25,7 @@ type App struct {
|
||||
activityStore *activity.Store
|
||||
alertStore *alerts.Store
|
||||
securityGuard *security.Guard
|
||||
appVersion string
|
||||
}
|
||||
|
||||
func Run(addr string) error {
|
||||
@@ -56,12 +59,14 @@ func Run(addr string) error {
|
||||
activityStore: activity.NewStore(filepath.Join(cfg.DBDir, "activity_log.json")),
|
||||
alertStore: alerts.NewStore(filepath.Join(cfg.DBDir, "alerts.json")),
|
||||
securityGuard: security.NewGuard(),
|
||||
appVersion: currentAppVersion(),
|
||||
}
|
||||
if err := app.reloadSecurityConfig(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
router := gin.Default()
|
||||
router.Use(app.versionHeaderMiddleware())
|
||||
router.Use(app.securityMiddleware())
|
||||
router.NoRoute(app.handleNoRoute)
|
||||
htmlTemplates, err := loadHTMLTemplates()
|
||||
@@ -149,3 +154,18 @@ func (app *App) handleHealth(c *gin.Context) {
|
||||
"status": "healthy",
|
||||
})
|
||||
}
|
||||
|
||||
func (app *App) versionHeaderMiddleware() gin.HandlerFunc {
|
||||
return func(ctx *gin.Context) {
|
||||
ctx.Header("X-App-Version", app.appVersion)
|
||||
ctx.Next()
|
||||
}
|
||||
}
|
||||
|
||||
func currentAppVersion() string {
|
||||
version := strings.TrimSpace(os.Getenv("APP_VERSION"))
|
||||
if version == "" {
|
||||
return "dev"
|
||||
}
|
||||
return version
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user