Skip to content

Commit

Permalink
chore: fix serve frontend flag
Browse files Browse the repository at this point in the history
  • Loading branch information
boojack committed Feb 20, 2024
1 parent fa62e8b commit 4a6da91
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
6 changes: 3 additions & 3 deletions bin/memos/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"go.uber.org/zap"

"github.com/usememos/memos/internal/jobs"

"github.com/usememos/memos/internal/log"
"github.com/usememos/memos/server"
_profile "github.com/usememos/memos/server/profile"
Expand Down Expand Up @@ -174,16 +173,17 @@ func initConfig() {

fmt.Printf(`---
Server profile
version: %s
data: %s
dsn: %s
addr: %s
port: %d
mode: %s
driver: %s
version: %s
frontend: %t
metric: %t
---
`, profile.Data, profile.DSN, profile.Addr, profile.Port, profile.Mode, profile.Driver, profile.Version, profile.Metric)
`, profile.Version, profile.Data, profile.DSN, profile.Addr, profile.Port, profile.Mode, profile.Driver, profile.Frontend, profile.Metric)
}

func printGreetings() {
Expand Down
4 changes: 2 additions & 2 deletions server/profile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ type Profile struct {
Driver string `json:"-"`
// Version is the current version of server
Version string `json:"version"`
// ServeFrontend indicate the frontend is enabled or not
ServeFrontend bool `json:"frontend"`
// Frontend indicate the frontend is enabled or not
Frontend bool `json:"-"`
// Metric indicate the metric collection is enabled or not
Metric bool `json:"-"`
}
Expand Down
15 changes: 3 additions & 12 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store
e.Use(CORSMiddleware())

e.Use(middleware.TimeoutWithConfig(middleware.TimeoutConfig{
Skipper: timeoutSkipper,
Skipper: grpcRequestSkipper,
Timeout: 30 * time.Second,
}))

Expand All @@ -69,8 +69,8 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store
}
s.ID = serverID

if profile.ServeFrontend {
// Register frontend service.
// Only serve frontend when it's enabled.
if profile.Frontend {
frontendService := frontend.NewFrontendService(profile, store)
frontendService.Serve(ctx, e)
}
Expand Down Expand Up @@ -174,15 +174,6 @@ func grpcRequestSkipper(c echo.Context) bool {
return strings.HasPrefix(c.Request().URL.Path, "/memos.api.v2.")
}

func timeoutSkipper(c echo.Context) bool {
if grpcRequestSkipper(c) {
return true
}

// Skip timeout for blob upload which is frequently timed out.
return c.Request().Method == http.MethodPost && c.Request().URL.Path == "/api/v1/resource/blob"
}

func CORSMiddleware() echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
Expand Down

0 comments on commit 4a6da91

Please sign in to comment.