Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional handler settings for SDK #77

Merged
merged 5 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (h *connectHandler) prepareConnection(ctx context.Context, data connectionE
return nil, false, fmt.Errorf("could not hash signing key: %w", err)
}

apiOrigin := defaultAPIOrigin
apiOrigin := h.h.GetAPIBaseURL()
if h.h.isDev() {
apiOrigin = DevServerURL()
}
Expand Down
2 changes: 1 addition & 1 deletion consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const (
)

const (
devServerOrigin = "http://127.0.0.1:8288"
defaultAPIOrigin = "https://api.inngest.com"
defaultEventAPIOrigin = "https://inn.gs"
devServerOrigin = "http://127.0.0.1:8288"
)
83 changes: 75 additions & 8 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@ type HandlerOpts struct {
// defaults to os.Getenv("INNGEST_SIGNING_KEY_FALLBACK").
SigningKeyFallback *string

// APIOrigin is the specified host to be used to make API calls
APIBaseURL *string

// EventAPIOrigin is the specified host to be used to send events to
EventAPIBaseURL *string

// ServeOrigin is the host to used for HTTP base function invoking.
// It's used to specify the host were the functions are hosted on sync.
// e.g. https://example.com
ServeOrigin *string

// ServePath is the path to use for HTTP base function invoking
// It's used to specify the path were the functions are hosted on sync.
// e.g. /api/inngest
ServePath *string

// Env is the branch environment to deploy to. If nil, this uses
// os.Getenv("INNGEST_ENV"). This only deploys to branches if the
// signing key is a branch signing key.
Expand Down Expand Up @@ -153,6 +169,57 @@ func (h HandlerOpts) GetSigningKeyFallback() string {
return *h.SigningKeyFallback
}

// GetAPIOrigin returns the host to use for sending API requests
func (h HandlerOpts) GetAPIBaseURL() string {
if h.isDev() {
return DevServerURL()
}

if h.APIBaseURL == nil {
base := os.Getenv("INNGEST_API_BASE_URL")
if base != "" {
return base
}

return defaultAPIOrigin
}

return *h.APIBaseURL
}

// GetEventAPIOrigin returns the host to use for sending events
func (h HandlerOpts) GetEventAPIBaseURL() string {
if h.isDev() {
return DevServerURL()
}

if h.EventAPIBaseURL == nil {
origin := os.Getenv("INNGEST_EVENT_API_BASE_URL")
if origin != "" {
return origin
}
return defaultEventAPIOrigin
}

return *h.EventAPIBaseURL
}

// GetServeOrigin returns the host used for HTTP based executions
func (h HandlerOpts) GetServeOrigin() string {
if h.ServeOrigin != nil {
return *h.ServeOrigin
}
return ""
}

// GetServePath returns the path used for HTTP based executions
func (h HandlerOpts) GetServePath() string {
if h.ServePath != nil {
return *h.ServePath
}
return ""
}

// GetEnv returns the env defined within HandlerOpts, or the default
// defined within INNGEST_ENV.
//
Expand Down Expand Up @@ -193,6 +260,14 @@ func (h HandlerOpts) GetWorkerConcurrency() int {
return h.WorkerConcurrency
}

func (h HandlerOpts) isDev() bool {
if h.Dev != nil {
return *h.Dev
}

return IsDev()
}

// Handler represents a handler which serves the Inngest API via HTTP. This provides
// function registration to Inngest, plus the invocation of registered functions via
// an HTTP POST.
Expand Down Expand Up @@ -637,14 +712,6 @@ func (h *handler) url(r *http.Request) *url.URL {
return u
}

func (h *handler) isDev() bool {
if h.Dev != nil {
return *h.Dev
}

return IsDev()
}

func createFunctionConfigs(
appName string,
fns []ServableFunction,
Expand Down
Loading