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, #s3_safe_name
Constructor Details
#initialize(port:, open_browser: false) ⇒ ServerCommand
Returns a new instance of ServerCommand.
68
69
70
71
72
73
|
# File 'lib/belt/cli/server_command.rb', line 68
def initialize(port:, open_browser: false)
@port = port
@open_browser = open_browser
@app_name = detect_app_name
@api_url = detect_api_url
end
|
Class Method Details
.help_text ⇒ Object
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
|
# File 'lib/belt/cli/server_command.rb', line 39
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})
-o, --open Open browser after starting
-h, --help Show this help
Behavior:
• If frontend/ exists → runs the frontend dev server (npm run dev)
Automatically sets VITE_API_URL from terraform outputs if deployed.
• 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 automatically points to
your deployed API via VITE_API_URL.
Examples:
belt server # Start on port #{DEFAULT_PORT}
belt s -p 4000 # Start on port 4000
belt s --open # Start and open browser
HELP
end
|
.run(args) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/belt/cli/server_command.rb', line 15
def self.run(args)
port = DEFAULT_PORT
open_browser = false
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).run
end
|
Instance Method Details
#run ⇒ Object
75
76
77
78
79
80
81
|
# File 'lib/belt/cli/server_command.rb', line 75
def run
if Dir.exist?('frontend') && File.exist?('frontend/package.json')
run_frontend_dev_server
else
run_welcome_server
end
end
|