Class: Belt::CLI::ServerCommand
- Inherits:
-
Object
- Object
- Belt::CLI::ServerCommand
show all
- Includes:
- AppDetection
- Defined in:
- lib/belt/cli/server_command.rb
Constant Summary
collapse
- DEFAULT_PORT =
3000
Class Method Summary
collapse
Instance Method Summary
collapse
#detect_app_name, #detect_environments, #detect_namespace, #find_contracts_file_path, #find_routes_file_path, #find_schema_file_path, #s3_safe_name
Constructor Details
#initialize(port:, open_browser: false, frontend_name: nil) ⇒ ServerCommand
Returns a new instance of ServerCommand.
74
75
76
77
78
79
80
81
|
# File 'lib/belt/cli/server_command.rb', line 74
def initialize(port:, open_browser: false, frontend_name: nil)
@port = port
@open_browser = open_browser
@frontend_name = frontend_name
@app_name = detect_app_name
@api_url = detect_api_url
@frontend = resolve_frontend
end
|
Class Method Details
.help_text ⇒ Object
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
71
72
|
# File 'lib/belt/cli/server_command.rb', line 42
def self.help_text
<<~HELP
Start a local development server for the frontend.
Usage: belt server [options]
belt s [options]
Options:
-p, --port PORT Port to serve on (default: #{DEFAULT_PORT})
--frontend NAME Which frontend to start (when several exist)
-o, --open Open browser after starting
-h, --help Show this help
Behavior:
• If a frontend exists → runs its dev server (npx vite)
Injects env from <frontend>/env.yml (or default VITE_API_URL) using
terraform outputs when available.
• If no frontend → serves the welcome page via a local HTTP server
After deploy, shows live API URL and deployment status.
Note: The backend is serverless (AWS Lambda). Use `belt deploy` to deploy
your backend to AWS. Local frontend development reads the env map (or
<frontend>/.env via `belt frontend env <env>`).
Examples:
belt server # Start on port #{DEFAULT_PORT}
belt s -p 4000 # Start on port 4000
belt s --frontend ops # Start the ops frontend
belt s --open # Start and open browser
HELP
end
|
.run(args) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/belt/cli/server_command.rb', line 17
def self.run(args)
port = DEFAULT_PORT
open_browser = false
frontend_name = FrontendRegistry.(args, '--frontend')
i = 0
while i < args.length
case args[i]
when '-p', '--port'
i += 1
port = args[i].to_i
when /^--port=/
port = args[i].split('=', 2).last.to_i
when '-o', '--open'
open_browser = true
when '-h', '--help'
puts help_text
exit 0
end
i += 1
end
new(port: port, open_browser: open_browser, frontend_name: frontend_name).run
end
|
Instance Method Details
#run ⇒ Object
83
84
85
86
87
88
89
|
# File 'lib/belt/cli/server_command.rb', line 83
def run
if @frontend&.exists?
run_frontend_dev_server
else
run_welcome_server
end
end
|