diff --git a/internal/cmd/start_api.go b/internal/cmd/start_api.go index acead65..c50471c 100644 --- a/internal/cmd/start_api.go +++ b/internal/cmd/start_api.go @@ -84,7 +84,7 @@ func StartApiCmdHandler(cmd *cobra.Command, args []string) { tenant.SingleTenantConfiguration(loadedConfig) case config.MultiTenant: default: - panic("Application mode is mandatory. Specify either 'single-tenant' or 'multi-tenant'.") + tenant.SingleTenantConfiguration(loadedConfig) } // Router diff --git a/internal/middleware/application_mode.go b/internal/middleware/application_mode.go index fe735cf..8c263a5 100644 --- a/internal/middleware/application_mode.go +++ b/internal/middleware/application_mode.go @@ -23,16 +23,23 @@ func SetApplicationMode() Middleware { // Define the http.HandlerFunc return func(w http.ResponseWriter, r *http.Request) { - if ApplicationMode == config.SingleTenant { + switch ApplicationMode { + case config.SingleTenant: + err := singleTenantConfig(r) + if err != nil { + m := "Failed to find organization" + common.HandleError(w, http.StatusBadRequest, m, err) + return + } - organization, err := org.GetFirstOrganization() + case config.MultiTenant: + default: + err := singleTenantConfig(r) if err != nil { m := "Failed to find organization" common.HandleError(w, http.StatusBadRequest, m, err) return } - organizationId := organization.ID.Hex() - r.Header.Set(config.OrganizationId, organizationId) } // Call the next middleware/handler in chain @@ -40,3 +47,14 @@ func SetApplicationMode() Middleware { } } } + +// singleTenantConfig +func singleTenantConfig(r *http.Request) error { + organization, err := org.GetFirstOrganization() + if err != nil { + return err + } + organizationId := organization.ID.Hex() + r.Header.Set(config.OrganizationId, organizationId) + return nil +}