1
0
Fork 0
mirror of https://github.com/muerwre/vk-tg-bot.git synced 2025-04-24 22:46:41 +07:00

getting webhook pathname from url

This commit is contained in:
Fedor Katurov 2021-04-26 12:46:42 +07:00
parent 87da9078fe
commit f444a7d194
3 changed files with 6 additions and 6 deletions

View file

@ -3,8 +3,7 @@ http:
telegram: telegram:
key: '' key: ''
webhook: webhook:
path: /webhook url: https://something.org:65534/webhook
url: https://something.org:123123/webhook
enabled: false enabled: false
logger: logger:
level: info level: info

View file

@ -7,6 +7,7 @@ import logger from "../../service/logger";
import { TelegramService } from "../../service/telegram"; import { TelegramService } from "../../service/telegram";
import http from "http"; import http from "http";
import { WebhookConfig } from "../../config/types"; import { WebhookConfig } from "../../config/types";
import url, { URL } from "url";
export class HttpApi { export class HttpApi {
app: Express; app: Express;
@ -37,9 +38,10 @@ export class HttpApi {
this.app.use(bodyParser.json()); this.app.use(bodyParser.json());
this.app.use(express.json()); this.app.use(express.json());
if (this?.webhook?.enabled && this?.webhook?.path) { if (this?.webhook?.enabled && this?.webhook?.url) {
logger.info(`using webhook at ${this.webhook.path}`); const url = new URL(this.webhook.url);
this.app.post(props.webhook.url, this.handleWebhook); logger.info(`using webhook at ${url.pathname}`);
this.app.post(url.pathname, this.handleWebhook);
} }
} }

View file

@ -4,7 +4,6 @@ import { HttpConfig } from "../api/http/types";
import { LoggerConfig } from "../service/logger/types"; import { LoggerConfig } from "../service/logger/types";
export interface WebhookConfig { export interface WebhookConfig {
path?: string;
url?: string; url?: string;
enabled?: boolean; enabled?: boolean;
} }