feat: const session secret key in dev

This commit is contained in:
email
2022-03-29 07:30:29 +08:00
parent 8f76120e4e
commit 1cebf1dbd0
5 changed files with 9 additions and 17 deletions

View File

@ -23,7 +23,7 @@ type Server struct {
port int
}
func NewServer(port int) *Server {
func NewServer(port int, mode string) *Server {
e := echo.New()
e.Debug = true
e.HideBanner = true
@ -46,7 +46,11 @@ func NewServer(port int) *Server {
HTML5: true,
}))
e.Use(session.Middleware(sessions.NewCookieStore([]byte(securecookie.GenerateRandomKey(16)))))
secret := []byte("justmemos")
if mode != "dev" {
secret = securecookie.GenerateRandomKey(16)
}
e.Use(session.Middleware(sessions.NewCookieStore(secret)))
s := &Server{
e: e,

View File

@ -11,8 +11,8 @@ import (
)
func (s *Server) registerUserRoutes(g *echo.Group) {
// GET /api/user/me is used to check if the user is logged in.
g.GET("/user/me", func(c echo.Context) error {
// /api/user/me is used to check if the user is logged in,
userSessionId := c.Get(getUserIdContextKey())
if userSessionId == nil {
return echo.NewHTTPError(http.StatusUnauthorized, "Missing session")

View File

@ -103,9 +103,8 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
}
c.Response().Writer.WriteHeader(http.StatusOK)
c.Response().Writer.Header().Set("Content-Type", "application/octet-stream")
c.Response().Writer.Header().Set("Content-Type", resource.Type)
c.Response().Writer.Write(resource.Blob)
return nil
})
}