From f444a7d194957eb0b14499e5d665a6eb302bff9f Mon Sep 17 00:00:00 2001 From: Fedor Katurov Date: Mon, 26 Apr 2021 12:46:42 +0700 Subject: [PATCH] getting webhook pathname from url --- config.example.yml | 3 +-- src/api/http/index.ts | 8 +++++--- src/config/types.ts | 1 - 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/config.example.yml b/config.example.yml index dcf6511..e386c83 100644 --- a/config.example.yml +++ b/config.example.yml @@ -3,8 +3,7 @@ http: telegram: key: '' webhook: - path: /webhook - url: https://something.org:123123/webhook + url: https://something.org:65534/webhook enabled: false logger: level: info diff --git a/src/api/http/index.ts b/src/api/http/index.ts index 6662b35..0a7090c 100644 --- a/src/api/http/index.ts +++ b/src/api/http/index.ts @@ -7,6 +7,7 @@ import logger from "../../service/logger"; import { TelegramService } from "../../service/telegram"; import http from "http"; import { WebhookConfig } from "../../config/types"; +import url, { URL } from "url"; export class HttpApi { app: Express; @@ -37,9 +38,10 @@ export class HttpApi { this.app.use(bodyParser.json()); this.app.use(express.json()); - if (this?.webhook?.enabled && this?.webhook?.path) { - logger.info(`using webhook at ${this.webhook.path}`); - this.app.post(props.webhook.url, this.handleWebhook); + if (this?.webhook?.enabled && this?.webhook?.url) { + const url = new URL(this.webhook.url); + logger.info(`using webhook at ${url.pathname}`); + this.app.post(url.pathname, this.handleWebhook); } } diff --git a/src/config/types.ts b/src/config/types.ts index 100f258..f6079aa 100644 --- a/src/config/types.ts +++ b/src/config/types.ts @@ -4,7 +4,6 @@ import { HttpConfig } from "../api/http/types"; import { LoggerConfig } from "../service/logger/types"; export interface WebhookConfig { - path?: string; url?: string; enabled?: boolean; }