Skip to content

Commit 27eb100

Browse files
committed
feat: add an env param "InSecure" to allow non-https deploy
1 parent 22f93ec commit 27eb100

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

.env

+3
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ PASSWORD="123"
77

88
# Path to store sqlite DB file
99
DB="fusion.db"
10+
11+
# Allow non-https request
12+
INSECURE=true

api/session.go

+7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ func (s Session) Create(c echo.Context) error {
2525
}
2626

2727
sess, _ := session.Get("login", c)
28+
29+
//使用非https请求时,为保证Set-Cookie能正常生效,对Option进行特殊设置
30+
if conf.Conf.InSecure {
31+
sess.Options.Secure = false
32+
sess.Options.SameSite = http.SameSiteDefaultMode
33+
}
34+
2835
sess.Values["password"] = conf.Conf.Password
2936
if err := sess.Save(c.Request(), c.Response()); err != nil {
3037
return c.NoContent(http.StatusInternalServerError)

conf/conf.go

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var Conf struct {
1313
Port int `mapstructure:"PORT"`
1414
Password string `mapstructure:"PASSWORD"`
1515
DB string
16+
InSecure bool `mapstructure:"INSECURE"`
1617
}
1718

1819
func Load() {

0 commit comments

Comments
 (0)