Skip to content

Commit

Permalink
hook for health checks, no need for hostname checking on oss routing
Browse files Browse the repository at this point in the history
  • Loading branch information
danenania committed Sep 26, 2024
1 parent a147b70 commit 0e791cd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
2 changes: 2 additions & 0 deletions app/server/hooks/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
)

const (
HealthCheck = "health_check"

CreateAccount = "create_account"
WillCreatePlan = "will_create_plan"
WillTellPlan = "will_tell_plan"
Expand Down
20 changes: 1 addition & 19 deletions app/server/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package main

import (
"fmt"
"log"
"os"
"plandex-server/setup"

"github.com/gorilla/mux"
Expand All @@ -13,25 +11,9 @@ func main() {
// Configure the default logger to include milliseconds in timestamps
log.SetFlags(log.LstdFlags | log.Lmicroseconds)

var domain string
if os.Getenv("DOMAIN") != "" {
domain = os.Getenv("DOMAIN")
} else if os.Getenv("GOENV") == "development" {
domain = "localhost"
} else {
panic(fmt.Errorf("DOMAIN environment variable is required unless GOENV is set to development"))
}

r := mux.NewRouter()

var apiRouter *mux.Router
if os.Getenv("GOENV") == "development" {
apiRouter = r
} else {
apiRouter = r.Host("api." + domain).Subrouter()
}

setup.MustLoadIp()
setup.MustInitDb()
setup.StartServer(apiRouter)
setup.StartServer(r)
}
11 changes: 11 additions & 0 deletions app/server/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@ package routes

import (
"fmt"
"log"
"net/http"
"os"
"plandex-server/handlers"
"plandex-server/hooks"

"github.com/gorilla/mux"
)

func AddApiRoutes(r *mux.Router) {
r.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {

_, apiErr := hooks.ExecHook(hooks.HealthCheck, hooks.HookParams{})

if apiErr != nil {
log.Printf("Error in health check hook: %v\n", apiErr)
http.Error(w, apiErr.Msg, apiErr.Status)
return
}

fmt.Fprint(w, "OK")
})

Expand Down

0 comments on commit 0e791cd

Please sign in to comment.