Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/EliasDeHondt/K10s
Browse files Browse the repository at this point in the history
  • Loading branch information
EliasDeHondt committed Feb 26, 2025
2 parents 24b3cda + ca1fd5d commit 764a30f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion App/Backend/cmd/auth/AuthHandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func IsLoggedIn(ctx *gin.Context) {
})

if err != nil || !token.Valid {
ctx.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "Invalid token"})
ctx.JSON(http.StatusOK, false)
return
}

Expand Down
5 changes: 4 additions & 1 deletion App/Backend/cmd/kubernetes/handlers/GetStats.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package handlers

import (
"fmt"
"github.com/gin-gonic/gin"
"net/http"
)
Expand All @@ -21,6 +22,7 @@ func GetStatsHandler(ctx *gin.Context) {
func GetTotalStats(ctx *gin.Context) {
metrics, err := c.GetTotalUsage()
if err != nil {
fmt.Printf("GetTotalStats err: %v\n", err)
ctx.JSON(http.StatusInternalServerError, gin.H{"error": "An error has occurred or the request has been timed out."})
return
}
Expand All @@ -30,8 +32,9 @@ func GetTotalStats(ctx *gin.Context) {
func GetStatsForNode(ctx *gin.Context, name string) {
metrics, err := c.GetUsageForNode(name)
if err != nil {
fmt.Printf("GetStatsForNode err: %v\n", err)
ctx.JSON(http.StatusInternalServerError, gin.H{"error": "An error has occurred or the request has been timed out."})
return
}
ctx.JSON(http.StatusOK, metrics)
}
}
14 changes: 13 additions & 1 deletion App/Backend/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,21 @@ import (

func main() {
frontendUrl := handlers.GetFrontendIP()
trustedProxies := []string{"10.0.0.0/8"}

if frontendUrl == "http://localhost:4200" {
gin.SetMode(gin.DebugMode)
} else {
gin.SetMode(gin.ReleaseMode)
}

r := gin.Default()

err := r.SetTrustedProxies(trustedProxies)
if err != nil {
panic(err)
}

r.Use(cors.New(cors.Config{
AllowOrigins: []string{frontendUrl},
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
Expand All @@ -43,7 +55,7 @@ func main() {
secured.GET("/stats", handlers.GetStatsHandler)
secured.POST("/createresources", handlers.CreateResourcesHandler)

err := r.Run(":8082")
err = r.Run(":8082")
if err != nil {
panic(err)
}
Expand Down

0 comments on commit 764a30f

Please sign in to comment.