@@ -40,7 +40,7 @@ import { randomUUID } from 'node:crypto';
4040import * as http from 'node:http' ;
4141import { DeliveryTimeout } from './bus.js' ;
4242import { appConfig } from './config.js' ;
43- import { isoUtc } from './envelope.js' ;
43+ import { asText , isoUtc } from './envelope.js' ;
4444import { getLogger } from './log.js' ;
4545import { FunctionRegistry } from './registry.js' ;
4646import { VERSION } from './version.js' ;
@@ -51,6 +51,23 @@ const INFO_TIMEOUT_MS = 3000; // engine value for the advisory type=info lookup
5151const HEALTH_TIMEOUT_MS = 10000 ; // engine value for the type=health probe
5252const UNHEALTHY = "Unhealthy. Please check '/health' endpoint." ;
5353
54+ // The engines' minimal landing page (platform-core public/index.html style);
55+ // the wrappers embed it - no static file service by design.
56+ const INDEX_HTML = `<!DOCTYPE html>
57+ <html>
58+ <body>
59+
60+ <h2>Welcome</h2>
61+
62+ <p><a href="/info">INFO endpoint</a></p>
63+ <p><a href="/info/routes">Service list</a></p>
64+ <p><a href="/env">Environment endpoint</a></p>
65+ <p><a href="/health">Health endpoint</a></p>
66+ <p><a href="/livenessprobe">Liveness probe</a></p>
67+
68+ </body>
69+ </html>` ;
70+
5471let origin : string | undefined ;
5572
5673/**
@@ -101,8 +118,8 @@ export function elapsedTime(milliseconds: number): string {
101118/** A comma/space-separated string (engine syntax) or a YAML list. */
102119function asList ( value : unknown ) : string [ ] {
103120 const items = Array . isArray ( value )
104- ? value . map ( ( item ) => String ( item ) . trim ( ) )
105- : String ( value ?? '' ) . split ( / [ , \s ] + / ) ;
121+ ? value . map ( ( item ) => asText ( item ) . trim ( ) )
122+ : asText ( value ?? '' ) . split ( / [ , \s ] + / ) ;
106123 return items . filter ( ( item ) => item . length > 0 ) ;
107124}
108125
@@ -113,13 +130,27 @@ function isMessageShape(body: unknown): boolean {
113130}
114131
115132function sendText ( res : http . ServerResponse , status : number , text : string ) : void {
116- res . writeHead ( status , { 'content-type' : 'text/plain' } ) ;
133+ res . writeHead ( status , { 'content-type' : 'text/plain; charset=utf-8 ' } ) ;
117134 res . end ( text ) ;
118135}
119136
120137function sendJson ( res : http . ServerResponse , status : number , body : unknown ) : void {
121- const bytes = Buffer . from ( JSON . stringify ( body ) ) ;
122- res . writeHead ( status , { 'content-type' : 'application/json' , 'content-length' : bytes . length } ) ;
138+ // the engines' default serializer presentation: pretty-printed JSON
139+ const bytes = Buffer . from ( JSON . stringify ( body , null , 2 ) ) ;
140+ res . writeHead ( status ,
141+ { 'content-type' : 'application/json; charset=utf-8' , 'content-length' : bytes . length } ) ;
142+ res . end ( bytes ) ;
143+ }
144+
145+ /** The engines' host-level error shape (SimpleHttpUtility signature). */
146+ export function sendError ( res : http . ServerResponse , status : number , message : string ) : void {
147+ sendJson ( res , status , { status, message, type : 'error' } ) ;
148+ }
149+
150+ function sendHtml ( res : http . ServerResponse , page : string ) : void {
151+ const bytes = Buffer . from ( page ) ;
152+ res . writeHead ( 200 ,
153+ { 'content-type' : 'text/html; charset=utf-8' , 'content-length' : bytes . length } ) ;
123154 res . end ( bytes ) ;
124155}
125156
@@ -153,6 +184,9 @@ export class Actuator {
153184 /** Route a GET to its actuator endpoint; false when the path is not ours. */
154185 async handle ( pathname : string , res : http . ServerResponse ) : Promise < boolean > {
155186 switch ( pathname ) {
187+ case '/' :
188+ sendHtml ( res , INDEX_HTML ) ;
189+ return true ;
156190 case '/info' :
157191 sendJson ( res , 200 , this . info ( ) ) ;
158192 return true ;
@@ -240,40 +274,44 @@ export class Actuator {
240274 for ( const route of services ) {
241275 const entry : Record < string , unknown > = { route, required } ;
242276 dependency . push ( entry ) ;
243- const service = this . registry . get ( route ) ;
244- if ( ! service ) {
277+ if ( ! await this . checkService ( route , entry ) ) {
245278 allUp = false ;
246- entry . status_code = 404 ;
247- entry . message = `Please check - Route ${ route } not found` ;
248- continue ;
249279 }
250- const bus = this . registry . bus ;
251- // info is advisory - merge whatever the service reports about itself;
252- // the health probe below decides the status
253- try {
254- const info = await bus . deliver ( service , { type : 'info' } , null , INFO_TIMEOUT_MS ) ;
255- if ( info . body !== null && typeof info . body === 'object' && ! Array . isArray ( info . body ) ) {
256- Object . assign ( entry , info . body ) ;
257- }
258- } catch ( e ) {
259- if ( ! ( e instanceof DeliveryTimeout ) ) throw e ;
280+ }
281+ return allUp ;
282+ }
283+
284+ /** Probe one health-check function; false when it is missing or down. */
285+ private async checkService ( route : string , entry : Record < string , unknown > ) : Promise < boolean > {
286+ const service = this . registry . get ( route ) ;
287+ if ( ! service ) {
288+ entry . status_code = 404 ;
289+ entry . message = `Please check - Route ${ route } not found` ;
290+ return false ;
291+ }
292+ const bus = this . registry . bus ;
293+ // info is advisory - merge whatever the service reports about itself;
294+ // the health probe below decides the status
295+ try {
296+ const info = await bus . deliver ( service , { type : 'info' } , null , INFO_TIMEOUT_MS ) ;
297+ if ( info . body !== null && typeof info . body === 'object' && ! Array . isArray ( info . body ) ) {
298+ Object . assign ( entry , info . body ) ;
260299 }
261- try {
262- const reply = await bus . deliver ( service , { type : 'health' } , null , HEALTH_TIMEOUT_MS ) ;
263- entry . status_code = reply . getStatus ( ) ;
264- if ( isMessageShape ( reply . body ) ) {
265- entry . message = reply . body ;
266- }
267- if ( reply . hasError ( ) ) {
268- allUp = false ;
269- }
270- } catch ( e ) {
271- if ( ! ( e instanceof DeliveryTimeout ) ) throw e ;
272- allUp = false ;
273- entry . status_code = 408 ;
274- entry . message = `Please check - ${ e . message } ` ;
300+ } catch ( e ) {
301+ if ( ! ( e instanceof DeliveryTimeout ) ) throw e ;
302+ }
303+ try {
304+ const reply = await bus . deliver ( service , { type : 'health' } , null , HEALTH_TIMEOUT_MS ) ;
305+ entry . status_code = reply . getStatus ( ) ;
306+ if ( isMessageShape ( reply . body ) ) {
307+ entry . message = reply . body ;
275308 }
309+ return ! reply . hasError ( ) ;
310+ } catch ( e ) {
311+ if ( ! ( e instanceof DeliveryTimeout ) ) throw e ;
312+ entry . status_code = 408 ;
313+ entry . message = `Please check - ${ e . message } ` ;
314+ return false ;
276315 }
277- return allUp ;
278316 }
279317}
0 commit comments