@@ -20,6 +20,8 @@ import passport from './utils/passport';
2020
2121const app : express . Application = express ( ) ;
2222
23+ const API_BASE_PATH = process . env . HYPERDX_API_BASE_PATH || '' ;
24+
2325const sess : session . SessionOptions & { cookie : session . CookieOptions } = {
2426 resave : false ,
2527 saveUninitialized : false ,
@@ -79,45 +81,84 @@ if (config.USAGE_STATS_ENABLED) {
7981// ---------------------------------------------------------------------
8082// ----------------------- Internal Routers ----------------------------
8183// ---------------------------------------------------------------------
82- // PUBLIC ROUTES
83- app . use ( '/' , routers . rootRouter ) ;
84+ if ( API_BASE_PATH ) {
85+ const apiRouter = express . Router ( ) ;
86+
87+ // PUBLIC ROUTES
88+ apiRouter . use ( '/' , routers . rootRouter ) ;
89+
90+ // PRIVATE ROUTES
91+ apiRouter . use ( '/alerts' , isUserAuthenticated , routers . alertsRouter ) ;
92+ apiRouter . use ( '/dashboards' , isUserAuthenticated , routers . dashboardRouter ) ;
93+ apiRouter . use ( '/me' , isUserAuthenticated , routers . meRouter ) ;
94+ apiRouter . use ( '/team' , isUserAuthenticated , routers . teamRouter ) ;
95+ apiRouter . use ( '/webhooks' , isUserAuthenticated , routers . webhooksRouter ) ;
96+ apiRouter . use ( '/connections' , isUserAuthenticated , connectionsRouter ) ;
97+ apiRouter . use ( '/sources' , isUserAuthenticated , sourcesRouter ) ;
98+ apiRouter . use ( '/saved-search' , isUserAuthenticated , savedSearchRouter ) ;
99+ apiRouter . use ( '/clickhouse-proxy' , isUserAuthenticated , clickhouseProxyRouter ) ;
100+ apiRouter . use ( '/api/v2' , externalRoutersV2 ) ;
101+
102+ // Only initialize Swagger in development or if explicitly enabled
103+ if (
104+ process . env . NODE_ENV !== 'production' &&
105+ process . env . ENABLE_SWAGGER === 'true'
106+ ) {
107+ import ( './utils/swagger' )
108+ . then ( ( { setupSwagger } ) => {
109+ console . log ( 'Swagger UI setup and available at /api/v2/docs' ) ;
110+ setupSwagger ( app ) ;
111+ } )
112+ . catch ( error => {
113+ console . error (
114+ 'Failed to dynamically load or setup Swagger. Swagger UI will not be available.' ,
115+ error ,
116+ ) ;
117+ } ) ;
118+ }
119+
120+ app . use ( API_BASE_PATH , apiRouter ) ;
121+ } else {
122+ // PUBLIC ROUTES
123+ app . use ( '/' , routers . rootRouter ) ;
84124
85- // PRIVATE ROUTES
86- app . use ( '/alerts' , isUserAuthenticated , routers . alertsRouter ) ;
87- app . use ( '/dashboards' , isUserAuthenticated , routers . dashboardRouter ) ;
88- app . use ( '/me' , isUserAuthenticated , routers . meRouter ) ;
89- app . use ( '/team' , isUserAuthenticated , routers . teamRouter ) ;
90- app . use ( '/webhooks' , isUserAuthenticated , routers . webhooksRouter ) ;
91- app . use ( '/connections' , isUserAuthenticated , connectionsRouter ) ;
92- app . use ( '/sources' , isUserAuthenticated , sourcesRouter ) ;
93- app . use ( '/saved-search' , isUserAuthenticated , savedSearchRouter ) ;
94- app . use ( '/clickhouse-proxy' , isUserAuthenticated , clickhouseProxyRouter ) ;
95- // ---------------------------------------------------------------------
125+ // PRIVATE ROUTES
126+ app . use ( '/alerts' , isUserAuthenticated , routers . alertsRouter ) ;
127+ app . use ( '/dashboards' , isUserAuthenticated , routers . dashboardRouter ) ;
128+ app . use ( '/me' , isUserAuthenticated , routers . meRouter ) ;
129+ app . use ( '/team' , isUserAuthenticated , routers . teamRouter ) ;
130+ app . use ( '/webhooks' , isUserAuthenticated , routers . webhooksRouter ) ;
131+ app . use ( '/connections' , isUserAuthenticated , connectionsRouter ) ;
132+ app . use ( '/sources' , isUserAuthenticated , sourcesRouter ) ;
133+ app . use ( '/saved-search' , isUserAuthenticated , savedSearchRouter ) ;
134+ app . use ( '/clickhouse-proxy' , isUserAuthenticated , clickhouseProxyRouter ) ;
135+
136+ // TODO: Separate external API routers from internal routers
137+ // ---------------------------------------------------------------------
138+ // ----------------------- External Routers ----------------------------
139+ // ---------------------------------------------------------------------
140+ // API v2
141+ // Only initialize Swagger in development or if explicitly enabled
142+ if (
143+ process . env . NODE_ENV !== 'production' &&
144+ process . env . ENABLE_SWAGGER === 'true'
145+ ) {
146+ import ( './utils/swagger' )
147+ . then ( ( { setupSwagger } ) => {
148+ console . log ( 'Swagger UI setup and available at /api/v2/docs' ) ;
149+ setupSwagger ( app ) ;
150+ } )
151+ . catch ( error => {
152+ console . error (
153+ 'Failed to dynamically load or setup Swagger. Swagger UI will not be available.' ,
154+ error ,
155+ ) ;
156+ } ) ;
157+ }
96158
97- // TODO: Separate external API routers from internal routers
98- // ---------------------------------------------------------------------
99- // ----------------------- External Routers ----------------------------
100- // ---------------------------------------------------------------------
101- // API v2
102- // Only initialize Swagger in development or if explicitly enabled
103- if (
104- process . env . NODE_ENV !== 'production' &&
105- process . env . ENABLE_SWAGGER === 'true'
106- ) {
107- import ( './utils/swagger' )
108- . then ( ( { setupSwagger } ) => {
109- console . log ( 'Swagger UI setup and available at /api/v2/docs' ) ;
110- setupSwagger ( app ) ;
111- } )
112- . catch ( error => {
113- console . error (
114- 'Failed to dynamically load or setup Swagger. Swagger UI will not be available.' ,
115- error ,
116- ) ;
117- } ) ;
159+ app . use ( '/api/v2' , externalRoutersV2 ) ;
118160}
119-
120- app . use ( '/api/v2' , externalRoutersV2 ) ;
161+ // ---------------------------------------------------------------------
121162
122163// error handling
123164app . use ( appErrorHandler ) ;
0 commit comments