99require_relative "../core/logger_factory"
1010require_relative "../core/log"
1111
12+ # import all core endpoint classes dynamically
13+ Dir [ File . join ( __dir__ , "endpoints/**/*.rb" ) ] . sort . each do |file |
14+ require file
15+ end
16+
1217module Hooks
1318 module App
1419 # Factory for creating configured Grape API classes
1520 class API
1621 include Hooks ::App ::Helpers
1722
23+ # Expose start_time for endpoint modules
24+ def self . start_time
25+ @start_time
26+ end
27+
1828 # Create a new configured API class
1929 def self . create ( config :, endpoints :, log :)
2030 # Store startup time for uptime calculation
21- start_time = Time . now
31+ @ start_time = Time . now
2232
2333 # Capture values in local variables for closure
2434 captured_config = config
2535 captured_endpoints = endpoints
2636 captured_logger = log
27- captured_start_time = start_time
2837
2938 # Set global logger instance for plugins/validators
3039 Hooks ::Log . instance = log
@@ -45,34 +54,9 @@ def self.create(config:, endpoints:, log:)
4554 # Define helper methods first, before routes
4655 helpers Helpers
4756
48- # Define operational endpoints
49- get captured_config [ :health_path ] do
50- content_type "application/json"
51- {
52- status : "healthy" ,
53- timestamp : Time . now . iso8601 ,
54- version : Hooks ::VERSION ,
55- uptime_seconds : ( Time . now - captured_start_time ) . to_i
56- } . to_json
57- end
58-
59- get captured_config [ :version_path ] do
60- content_type "application/json"
61- {
62- version : Hooks ::VERSION ,
63- timestamp : Time . now . iso8601
64- } . to_json
65- end
66-
67- # Hello world demo endpoint
68- get "#{ captured_config [ :root_path ] } /hello" do
69- content_type "application/json"
70- {
71- message : "hooks is working!" ,
72- version : Hooks ::VERSION ,
73- timestamp : Time . now . iso8601
74- } . to_json
75- end
57+ # Mount split-out endpoints
58+ mount Hooks ::App ::HealthEndpoint => config [ :health_path ]
59+ mount Hooks ::App ::VersionEndpoint => config [ :version_path ]
7660
7761 # Define webhook endpoints dynamically
7862 captured_endpoints . each do |endpoint_config |
@@ -82,7 +66,6 @@ def self.create(config:, endpoints:, log:)
8266 # Use send to dynamically create POST route
8367 send ( :post , full_path ) do
8468 request_id = SecureRandom . uuid
85- start_time = Time . now
8669
8770 # Use captured values
8871 config = captured_config
@@ -161,7 +144,6 @@ def self.create(config:, endpoints:, log:)
161144 if captured_config [ :use_catchall_route ]
162145 post "#{ captured_config [ :root_path ] } /*path" do
163146 request_id = SecureRandom . uuid
164- start_time = Time . now
165147
166148 # Use captured values
167149 config = captured_config
0 commit comments