From 139eda2dba71151df3c21c26146cb74b2d7e2e37 Mon Sep 17 00:00:00 2001 From: 0xZensh Date: Sun, 24 Sep 2023 09:57:35 +0800 Subject: [PATCH] fix: fix cookie domain; add env cookie --- src/app/app.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/app/app.go b/src/app/app.go index 1e7a351..d919087 100644 --- a/src/app/app.go +++ b/src/app/app.go @@ -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) @@ -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, }) }