Skip to content

Commit

Permalink
Merge pull request #54 from OOrangeeee/online/deploy-debug
Browse files Browse the repository at this point in the history
feat(ci/cd):add (ci/cd)
  • Loading branch information
OOrangeeee authored Oct 14, 2024
2 parents e598255 + 6e2deba commit 1782cd6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
4 changes: 1 addition & 3 deletions cmd/SEP/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ import (
"SEP/internal/router"
"SEP/internal/utils"
"github.com/labstack/echo/v4"
"os"
)

func main() {
e := echo.New()
jwtS := os.Getenv("JWT_SECRET")
utils.InitLog()
configs.InitViper()
utils.InitDB()
configs.InitMiddleware(e, jwtS)
configs.InitMiddleware(e)
router.GetRouterConfig(e)
router.PostRouterConfig(e)
router.PutRouterConfig(e)
Expand Down
12 changes: 6 additions & 6 deletions internal/configs/middlewareConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import (
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
"net/http"
"os"
"path/filepath"
)

func InitMiddleware(e *echo.Echo, jwtSecret string) {
func InitMiddleware(e *echo.Echo) {

//recover
e.Use(middleware.Recover())
Expand Down Expand Up @@ -77,17 +78,16 @@ func InitMiddleware(e *echo.Echo, jwtSecret string) {
if (c.Path() == "/users" && c.Request().Method == "GET") || (c.Path() == "/users" && c.Request().Method == "DELETE") || (c.Path() == "/config" && c.Request().Method == "PUT") || (c.Path() == "/csrf-token" && c.Request().Method == "GET") || (c.Path() == "/users/account/activation/:activationCode" && c.Request().Method == "GET") || (c.Path() == "/users/account" && c.Request().Method == "POST") || (c.Path() == "/users/login" && c.Request().Method == "POST") {
return true
}
utils.Log.WithFields(logrus.Fields{
"jwtSecret": jwtSecret,
}).Info("JWT中间件启用")
return false
},
SigningKey: []byte(jwtSecret),
SigningKey: func(c echo.Context) []byte {
return []byte(viper.GetString("jwt.jwtSecret"))
},
TokenLookup: "header:Authorization:Bearer ",
ErrorHandler: func(c echo.Context, err error) error {
utils.Log.WithFields(logrus.Fields{
"error": err.Error(),
"jwtS": jwtSecret,
"jwtS": viper.GetString("jwt.jwtSecret"),
"jwt": c.Request().Header.Get("Authorization"),
}).Error("JWT validation failed")
return echo.NewHTTPError(http.StatusUnauthorized, "Invalid or expired JWT")
Expand Down

0 comments on commit 1782cd6

Please sign in to comment.