diff --git a/http/admin/login.go b/http/admin/login.go index 12a9d28..b4df1fd 100644 --- a/http/admin/login.go +++ b/http/admin/login.go @@ -47,4 +47,4 @@ func handleLogin(w http.ResponseWriter, r *http.Request) { session.Add(sess, w) http.Redirect(w, r, "/admin/panel.html", http.StatusSeeOther) -} +} \ No newline at end of file diff --git a/http/middle/session.go b/http/middle/session.go index 580d778..54b0610 100644 --- a/http/middle/session.go +++ b/http/middle/session.go @@ -2,12 +2,16 @@ package middle import ( "github.com/icza/session" + "go.rls.moe/nyx/config" "net/http" ) -func init() { +func SetupSessionManager(c *config.Config) { session.Global.Close() - session.Global = session.NewCookieManager(session.NewInMemStore()) + session.Global = session.NewCookieManagerOptions(session.NewInMemStore(), + &session.CookieMngrOptions{ + AllowHTTP: c.DisableSecurity, + }) } func GetSession(r *http.Request) session.Session { diff --git a/http/server.go b/http/server.go index 4f41c83..ad9d6f9 100644 --- a/http/server.go +++ b/http/server.go @@ -14,14 +14,6 @@ import ( "time" ) -var riceConf = rice.Config{ - LocateOrder: []rice.LocateMethod{ - rice.LocateWorkingDirectory, - rice.LocateEmbedded, - rice.LocateAppended, - }, -} - func Start(config *config.Config) error { err := admin.LoadTemplates() if err != nil { @@ -35,6 +27,7 @@ func Start(config *config.Config) error { if err != nil { return err } + middle.SetupSessionManager(config) r := chi.NewRouter()