UNPKG

ipfsd-ctl

Version:
40 lines 1.01 kB
import Hapi from '@hapi/hapi'; import routes from './routes.js'; /** * Creates an instance of Server */ class Server { constructor(options = { port: 43134, host: 'localhost' }, createFactory) { this.options = options; this.server = null; this.port = this.options.port ?? 43134; this.host = this.options.host ?? 'localhost'; this.createFactory = createFactory; } /** * Start the server */ async start(port = this.port) { this.port = port; this.server = new Hapi.Server({ port: port, host: this.host, routes: { cors: true } }); routes(this.server, this.createFactory); await this.server.start(); return this; } /** * Stop the server */ async stop(options) { if (this.server != null) { await this.server.stop(options); } } } export default Server; //# sourceMappingURL=server.js.map