File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed
Elastic.Documentation.Site/Assets/web-components/SearchOrAskAi
api/Elastic.Documentation.Api.Infrastructure Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import {
1515import { css } from '@emotion/react'
1616import * as React from 'react'
1717import { useEffect , Suspense , lazy } from 'react'
18+ import { useQuery } from '@tanstack/react-query'
1819
1920// Lazy load the modal component
2021const SearchOrAskAiModal = lazy ( ( ) =>
@@ -28,6 +29,16 @@ export const SearchOrAskAiButton = () => {
2829 const { clearSearchTerm } = useSearchActions ( )
2930 const isModalOpen = useModalIsOpen ( )
3031 const { openModal, closeModal, toggleModal } = useModalActions ( )
32+
33+ const { data : isApiAvailable } = useQuery ( {
34+ queryKey : [ 'api-health' ] ,
35+ queryFn : async ( ) => {
36+ const response = await fetch ( '/docs/_api/v1/' , { method : 'HEAD' } )
37+ return response . ok
38+ } ,
39+ staleTime : 5 * 60 * 1000 , // 5 minutes
40+ retry : false
41+ } )
3142
3243 const positionCss = css `
3344 position : absolute;
@@ -61,6 +72,10 @@ export const SearchOrAskAiButton = () => {
6172 window . removeEventListener ( 'keydown' , handleKeydown )
6273 }
6374 } , [ ] )
75+
76+ if ( ! isApiAvailable ) {
77+ return null
78+ }
6479
6580 return (
6681 < >
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ public static class MappingsExtension
1515{
1616 public static void MapElasticDocsApiEndpoints ( this IEndpointRouteBuilder group )
1717 {
18+ _ = group . MapMethods ( "/" , [ HttpMethods . Head ] , ( ) => Results . Empty ) ;
1819 MapAskAiEndpoint ( group ) ;
1920 MapSearchEndpoint ( group ) ;
2021 }
You can’t perform that action at this time.
0 commit comments