import { FastifyInstance, FastifyReply, FastifyRequest, FastifyError } from 'fastify'; import { Executor } from '../base/Executor'; import { HttpAddressInitializer, Addresses } from '../base/Transports'; import { TcpServer } from '../tcp/TcpServer'; /** * A `Server` for the HTTP transport. * * This server class performs JSON-RPC over HTTP. * * For the `POST /` route, the request body should be * a JSON-RPC request. The response body will be * a JSON-RPC response. * * For the `POST /` routes, the request body should * correspond to the `params` property of a JSON-RPC request. * The response body corresponds to the `result` property of * a JSON-RPC response for `200 OK` responses and the `error` * property otherwise. */ export declare class HttpServer extends TcpServer { /** * The Fastify application. * * Used by derived classes to add routes. */ protected app?: FastifyInstance; /** * The secret used to decode JWT tokens. * * If this is not provided to the constructor * then a random secret will be generated and * logged for use in generating tokens. */ readonly jwtSecret: string; constructor(address?: HttpAddressInitializer, jwtSecret?: string); /** * @override Overrides {@link TcpServer.addresses} * to provide a HTTP entry. */ addresses(): Promise; /** * Build the Fastify app. * * Derived classes may want to override this method * to extend the set of endpoints etc. */ protected buildApp(): Promise; /** * Hook that performs JWT verification on each request */ protected onRequest(request: FastifyRequest, reply: FastifyReply): Promise; /** * Custom 404 handler which returns a JSON-RPC error * (not wrapped in a JSON-RPC response) intended as a reply * to wrong RESTful-like routes e.g. `/exec` instead of `/execute` */ protected notFoundHandler(request: FastifyRequest, reply: FastifyReply): void; /** * Custom error handler to return a JSON-RPC response * with an `error` property. */ protected errorHandler(error: FastifyError, request: FastifyRequest, reply: FastifyReply): void; start(executor: Executor): Promise; /** * @override Overrides {@link TcpServer.stop} to close * Fastify app. */ stop(): Promise; }