public ProteusApplication addDefaultRoutes ( RoutingHandler router ) { if ( config . hasPath ( "health.statusPath" ) ) { try { final String statusPath = config . getString ( "health.statusPath" ) ; router . add ( Methods . GET , statusPath , ( final HttpServerExchange exchange ) -> { exchange . getResponseHeaders ( ) . add ( Headers . CONTENT_TYPE , MediaType . TEXT_PLAIN ) ; exchange . getResponseSender ( ) . send ( "OK" ) ; } ) ; this . registeredEndpoints . add ( EndpointInfo . builder ( ) . withConsumes ( "*/*" ) . withProduces ( "text/plain" ) . withPathTemplate ( statusPath ) . withControllerName ( "Internal" ) . withMethod ( Methods . GET ) . build ( ) ) ; } catch ( Exception e ) { log . error ( "Error adding health status route." , e . getMessage ( ) ) ; } } if ( config . hasPath ( "application.favicon" ) ) { try { final ByteBuffer faviconImageBuffer ; final File faviconFile = new File ( config . getString ( "application.favicon" ) ) ; if ( ! faviconFile . exists ( ) ) { try ( final InputStream stream = this . getClass ( ) . getResourceAsStream ( config . getString ( "application.favicon" ) ) ) { ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; byte [ ] buffer = new byte [ 4096 ] ; int read = 0 ; while ( read != - 1 ) { read = stream . read ( buffer ) ; if ( read > 0 ) { baos . write ( buffer , 0 , read ) ; } } faviconImageBuffer = ByteBuffer . wrap ( baos . toByteArray ( ) ) ; } } else { try ( final InputStream stream = Files . newInputStream ( Paths . get ( config . getString ( "application.favicon" ) ) ) ) { ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; byte [ ] buffer = new byte [ 4096 ] ; int read = 0 ; while ( read != - 1 ) { read = stream . read ( buffer ) ; if ( read > 0 ) { baos . write ( buffer , 0 , read ) ; } } faviconImageBuffer = ByteBuffer . wrap ( baos . toByteArray ( ) ) ; } } router . add ( Methods . GET , "favicon.ico" , ( final HttpServerExchange exchange ) -> { exchange . getResponseHeaders ( ) . add ( Headers . CONTENT_TYPE , io . sinistral . proteus . server . MediaType . IMAGE_X_ICON . toString ( ) ) ; exchange . getResponseSender ( ) . send ( faviconImageBuffer ) ; } ) ; } catch ( Exception e ) { log . error ( "Error adding favicon route." , e . getMessage ( ) ) ; } } return this ; }
Add utility routes the router