kibana源码分析-3

src\core\server\http\http_service.js

负责web服务器的运行

async start() { const config = await this.config$.pipe((0, _operators.first)()).toPromise(); if (this.shouldListen(config)) { if (this.notReadyServer) { this.log.debug(stopping NotReady server); await this.notReadyServer.stop(); this.notReadyServer = ; } // If a redirect port is specified, we start an HTTP server at this port and // redirect all requests to the SSL port. if (config.ssl.enabled && config.ssl.redirectHttpFromPort !== ) { await this.httpsRedirectServer.start(config); } await this.httpServer.start(); } return this.getStartContract(); }

src\core\server\http\http_server.js

定义了httpServer.start() function以及route相关参数

async start() { if (this.server === ) { throw new Error(Http server is not setup up yet); } if (this.stopped) { this.log.warn(`start called after stop`); return; } this.log.debug(starting http server); for (const router of this.registeredRouters) { for (const route of router.getRoutes()) { var _route$options$xsrfRe; this.log.debug(`registering route handler for [${route.path}]`); // Hapi does not allow payload validation to be specified for head or get requests const validate = (0, _router.isSafeMethod)(route.method) ?: { payload: true }; const { authRequired, tags, body = {}, timeout } = route.options; const { accepts: allow, maxBytes, output, parse } = body; // Hapi does not allow timeouts on payloads to be specified for head or get requests const payloadTimeout = (0, _router.isSafeMethod)(route.method) || timeout == null ?: timeout; const kibanaRouteState = { xsrfRequired: (_route$options$xsrfRe = route.options.xsrfRequired) !== null && _route$options$xsrfRe !== void 0 ? _route$options$xsrfRe : !(0, _router.isSafeMethod)(route.method) }; this.server.route({ handler: route.handler, method: route.method, path: route.path, options: { auth: this.getAuthOption(authRequired), app: kibanaRouteState, tags: tags ? Array.from(tags) : , // TODO: This validate section can be removed once the legacy platform is completely removed. // We are telling Hapi that NP routes can accept any payload, so that it can bypass the default // validation applied in ./http_tools#getServerOptions // (All NP routes are already required to specify their own validation in order to access the payload) validate, payload: [allow, maxBytes, output, parse, payloadTimeout].some(v => typeof v !== ) ? { allow, maxBytes, output, parse, timeout: payloadTimeout } : , timeout: timeout != null ? { socket: timeout + 1 // Hapi server requires the socket to be greater than payload settings so we add 1 millisecond } : } }); } } await this.server.start(); const serverPath = this.config && this.config.rewriteBasePath && this.config.basePath !==? this.config.basePath : ; this.log.info(`http server running at ${this.server.info.uri}${serverPath}`);

this.registeredRouters 定义所有可用Route