Skip to content

Commit

Permalink
fix: fix cookie domain; add env cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed Sep 24, 2023
1 parent 2d5ff40 commit 139eda2
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ func handleContext(ctx *gear.Context) (lang string) {
logging.SetTo(ctx, "ccy", cookie.Value)
}

domain := conf.Config.Cookie.Domain
if strings.HasSuffix(ctx.Host, "yiwen.pub") {
domain = "yiwen.pub"
}

// 用户推荐人
if cookie, _ := ctx.Req.Cookie("by"); cookie != nil {
logging.SetTo(ctx, "by", cookie.Value)
Expand All @@ -199,7 +204,21 @@ func handleContext(ctx *gear.Context) (lang string) {
Secure: conf.Config.Cookie.Secure,
MaxAge: int(conf.Config.Cookie.ExpiresIn),
Path: "/",
Domain: conf.Config.Cookie.Domain,
Domain: domain,
SameSite: http.SameSiteLaxMode,
})
}

if env := ctx.Query("env"); len(env) > 0 {
logging.SetTo(ctx, "env", env)
http.SetCookie(ctx.Res, &http.Cookie{
Name: "env",
Value: env,
HttpOnly: true,
Secure: conf.Config.Cookie.Secure,
MaxAge: int(conf.Config.Cookie.ExpiresIn),
Path: "/",
Domain: domain,
SameSite: http.SameSiteLaxMode,
})
}
Expand Down

0 comments on commit 139eda2

Please sign in to comment.