Skip to content

Commit

Permalink
feat: add an env param "InSecure" to allow non-https deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnathanLin committed Aug 1, 2024
1 parent 22f93ec commit 27eb100
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ PASSWORD="123"

# Path to store sqlite DB file
DB="fusion.db"

# Allow non-https request
INSECURE=true
7 changes: 7 additions & 0 deletions api/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ func (s Session) Create(c echo.Context) error {
}

sess, _ := session.Get("login", c)

//使用非https请求时,为保证Set-Cookie能正常生效,对Option进行特殊设置
if conf.Conf.InSecure {
sess.Options.Secure = false
sess.Options.SameSite = http.SameSiteDefaultMode
}

sess.Values["password"] = conf.Conf.Password
if err := sess.Save(c.Request(), c.Response()); err != nil {
return c.NoContent(http.StatusInternalServerError)
Expand Down
1 change: 1 addition & 0 deletions conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var Conf struct {
Port int `mapstructure:"PORT"`
Password string `mapstructure:"PASSWORD"`
DB string
InSecure bool `mapstructure:"INSECURE"`
}

func Load() {
Expand Down

0 comments on commit 27eb100

Please sign in to comment.