import { RouteOptionsCors , ServerOptions } from '@hapi/hapi' ; import { ServerOptions as TLSOptions } from 'https' ; import { defaultValidationErrorHandler } from './default_validation_error_handler' ; import { IHttpConfig } from './types' ; const corsAllowedHeaders = [ 'Accept' , 'Authorization' , 'Content-Type' , 'If-None-Match' , 'kbn-xsrf' ] ; /**
 * Converts Kibana `HttpConfig` into `ServerOptions` that are accepted by the Hapi server.
 */ export function getServerOptions ( config , { configureTLS = true } = { } ) { const cors = config . cors . enabled ? { credentials : config . cors . allowCredentials , origin : config . cors . allowOrigin , headers : corsAllowedHeaders , } : false ; const options = { host : config . host , port : config . port , routes : { cache : { privacy : 'private' , otherwise : 'private, no-cache, no-store, must-revalidate' , } , cors , payload : { maxBytes : config . maxPayload . getValueInBytes ( ) , } , validate : { failAction : defaultValidationErrorHandler , options : { abortEarly : false , } , } , } , state : { strictHeader : false , isHttpOnly : true , isSameSite : false , } , } ; if ( configureTLS && config . ssl . enabled ) { const ssl = config . ssl ; const tlsOptions = { ca : ssl . certificateAuthorities , cert : ssl . certificate , ciphers : config . ssl . cipherSuites ?. join ( ':' ) , honorCipherOrder : true , key : ssl . key , passphrase : ssl . keyPassphrase , secureOptions : ssl . getSecureOptions ? ssl . getSecureOptions ( ) : undefined , requestCert : ssl . requestCert , rejectUnauthorized : ssl . rejectUnauthorized , } ; options . tls = tlsOptions ; } return options ; }