Skip to content

Commit

Permalink
Merge pull request #1483 from teamkeel/main
Browse files Browse the repository at this point in the history
feat: custom hostname for `keel run` (#1482)
  • Loading branch information
davenewza authored Apr 29, 2024
2 parents 3c27c27 + 6c64131 commit b587c22
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 5 deletions.
Binary file added cmd/keel/__debug_bin2873130161
Binary file not shown.
8 changes: 6 additions & 2 deletions cmd/program/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,13 @@ type RuntimeRequestMsg struct {
done chan bool
}

func StartRuntimeServer(port string, ch chan tea.Msg) tea.Cmd {
func StartRuntimeServer(port string, customHostname string, ch chan tea.Msg) tea.Cmd {
return func() tea.Msg {
os.Setenv("KEEL_API_URL", fmt.Sprintf("http://localhost:%s", port))
if customHostname != "" {
os.Setenv("KEEL_API_URL", customHostname)
} else {
os.Setenv("KEEL_API_URL", fmt.Sprintf("http://localhost:%s", port))
}

runtimeServer := http.Server{
Addr: fmt.Sprintf(":%s", port),
Expand Down
5 changes: 4 additions & 1 deletion cmd/program/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ type Model struct {
// This will then show all system events in the local console.
VerboseTracing bool

// A custom configured hostname, which may be necessary to change for SSO callback.
CustomHostname string

// Model state - used in View()
Status int
Err error
Expand Down Expand Up @@ -300,7 +303,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.Status = StatusLoadSchema

cmds := []tea.Cmd{
StartRuntimeServer(m.Port, m.runtimeRequestsCh),
StartRuntimeServer(m.Port, m.CustomHostname, m.runtimeRequestsCh),
StartRpcServer(m.RpcPort, m.rpcRequestsCh),
NextMsgCommand(m.runtimeRequestsCh),
NextMsgCommand(m.rpcRequestsCh),
Expand Down
6 changes: 5 additions & 1 deletion cmd/program/views.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ func renderRun(m *Model) string {
for _, values := range endpoints {
b.WriteString("\n")
b.WriteString(" - ")
b.WriteString(colors.Blue(fmt.Sprintf("http://localhost:%s/%s/%s", m.Port, strings.ToLower(api.Name), values[0])).Highlight().String())
if m.CustomHostname == "" {
b.WriteString(colors.Blue(fmt.Sprintf("http://localhost:%s/%s/%s", m.Port, strings.ToLower(api.Name), values[0])).Highlight().String())
} else {
b.WriteString(colors.Blue(fmt.Sprintf("%s/%s/%s", m.CustomHostname, strings.ToLower(api.Name), values[0])).Highlight().String())
}
b.WriteString(colors.White(fmt.Sprintf(" (%s)", values[1])).String())
}
b.WriteString("\n")
Expand Down
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var (
flagVersion bool
flagVerboseTracing bool
flagEnvironment string
flagHostname string
)

var rootCmd = &cobra.Command{
Expand Down
4 changes: 3 additions & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var runCmd = &cobra.Command{
ProjectDir: flagProjectDir,
ResetDatabase: flagReset,
Port: flagPort,
CustomHostname: flagHostname,
CustomTracing: flagTracing,
NodePackagesPath: flagNodePackagesPath,
PackageManager: packageManager,
Expand All @@ -36,7 +37,8 @@ func init() {
rootCmd.AddCommand(runCmd)

runCmd.Flags().BoolVar(&flagReset, "reset", false, "if set the database will be reset")
runCmd.Flags().StringVar(&flagPort, "port", "8000", "the port to run the Keel application on")
runCmd.Flags().StringVar(&flagHostname, "hostname", "", "custom hostname to handle HTTP requests")
runCmd.Flags().StringVar(&flagPort, "port", "8000", "the local port to handle Keel HTTP requests")
runCmd.Flags().StringVar(&flagPrivateKeyPath, "private-key-path", "", "path to the private key .pem file")

if enabledDebugFlags == "true" {
Expand Down

0 comments on commit b587c22

Please sign in to comment.