-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathserver.go
More file actions
70 lines (57 loc) · 2.12 KB
/
server.go
File metadata and controls
70 lines (57 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package cmd
import (
"github.com/spf13/cobra"
"github.com/xavidop/voiceflow-cli/internal/global"
"github.com/xavidop/voiceflow-cli/internal/openai"
"github.com/xavidop/voiceflow-cli/internal/voiceflow"
"github.com/xavidop/voiceflow-cli/server"
)
// serverCmd represents the server command
var serverCmd = &cobra.Command{
Use: "server",
Short: "Start the Voiceflow CLI API server",
Long: `Start the Voiceflow CLI API server to expose test execution endpoints.
The server provides HTTP endpoints for:
- Executing test suites
- Checking test execution status
- Retrieving system information
The server includes auto-generated OpenAPI/Swagger documentation available at /swagger/index.html`,
Example: ` # Start server on default port (8080)
voiceflow server
# Start server on custom port
voiceflow server --port 9090
# Start server with debug mode
voiceflow server --debug
# Start server with custom host
voiceflow server --host 127.0.0.1 --port 8080`,
Run: func(cmd *cobra.Command, args []string) {
port, _ := cmd.Flags().GetString("port")
host, _ := cmd.Flags().GetString("host")
debug, _ := cmd.Flags().GetBool("debug")
corsEnabled, _ := cmd.Flags().GetBool("cors")
swaggerEnabled, _ := cmd.Flags().GetBool("swagger")
voiceflow.SetVoiceflowAPIKey()
openai.SetOpenAIAPIKey()
// Enable tester messages in server mode for better observability
global.ShowTesterMessages = true
config := &server.ServerConfig{
Port: port,
Host: host,
Debug: debug,
CORSEnabled: corsEnabled,
SwaggerEnabled: swaggerEnabled,
}
srv := server.NewServer(config)
if err := srv.Start(); err != nil {
global.Log.Fatalf("Failed to start server: %v", err)
}
},
}
func init() {
rootCmd.AddCommand(serverCmd)
serverCmd.Flags().StringP("port", "p", "8080", "Port to run the server on")
serverCmd.Flags().StringP("host", "H", "0.0.0.0", "Host to bind the server to")
serverCmd.Flags().BoolP("debug", "d", false, "Enable debug mode")
serverCmd.Flags().Bool("cors", true, "Enable CORS middleware")
serverCmd.Flags().Bool("swagger", true, "Enable Swagger documentation endpoint")
}