UNPKG

@twurple/eventsub-ngrok

Version:

Test your EventSub listener locally using ngrok.

48 lines (47 loc) 1.46 kB
import { __decorate } from "tslib"; import { Enumerable } from '@d-fischer/shared-utils'; import { connect } from '@ngrok/ngrok'; import { ConnectionAdapter } from '@twurple/eventsub-http'; /** * A connection adapter that uses ngrok to make local testing easy. */ export class NgrokAdapter extends ConnectionAdapter { /** @internal */ _listenerPort; /** @internal */ _ngrokConfig; /** @internal */ _hostNamePromise; /** * Creates a new instance of the `NgrokAdapter`. * * @expandParams * * @param config */ constructor(config = {}) { super(); this._listenerPort = config.port ?? 8000; this._ngrokConfig = config.ngrokConfig; } /** @protected */ // eslint-disable-next-line @typescript-eslint/class-literal-property-style get connectUsingSsl() { return true; } /** @protected */ get listenerPort() { return this._listenerPort; } /** @protected */ async getHostName() { this._hostNamePromise ??= connect({ ...this._ngrokConfig, addr: this._listenerPort }).then(url => url.replace(/^https?:\/\/|\/$/g, '')); return await this._hostNamePromise; } } __decorate([ Enumerable(false) ], NgrokAdapter.prototype, "_listenerPort", void 0); __decorate([ Enumerable(false) ], NgrokAdapter.prototype, "_ngrokConfig", void 0); __decorate([ Enumerable(false) ], NgrokAdapter.prototype, "_hostNamePromise", void 0);