From a4b0145832b4ee012780b5740bd45e1f7a4132f5 Mon Sep 17 00:00:00 2001 From: Grzegorz Godlewski Date: Fri, 26 Jul 2024 16:20:01 +0200 Subject: [PATCH] Add webhook endpoint --- src/containers/server/ServerContainer.ts | 4 ++++ .../server/routes/WebHookController.ts | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/containers/server/routes/WebHookController.ts diff --git a/src/containers/server/ServerContainer.ts b/src/containers/server/ServerContainer.ts index fbf89385..7d59d26a 100644 --- a/src/containers/server/ServerContainer.ts +++ b/src/containers/server/ServerContainer.ts @@ -44,6 +44,7 @@ import {GoogleTreeProcessor} from '../google_folder/GoogleTreeProcessor.ts'; import {initStaticDistPages} from './static.ts'; import {initUiServer} from './vuejs.ts'; import {initErrorHandler} from './error.ts'; +import {WebHookController} from './routes/WebHookController.js'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); @@ -256,6 +257,9 @@ export class ServerContainer extends Container { const driveUiController = new DriveUiController('/driveui', this.logger, this.filesService, this.authContainer); app.use('/driveui', await driveUiController.getRouter()); + const webHookController = new WebHookController('/webhook', this.logger); + app.use('/webhook', await webHookController.getRouter()); + app.use('/api/share-token', authenticate(this.logger), (req, res) => { if ('POST' !== req.method) { throw new Error('Incorrect method'); diff --git a/src/containers/server/routes/WebHookController.ts b/src/containers/server/routes/WebHookController.ts new file mode 100644 index 00000000..52b8c8c6 --- /dev/null +++ b/src/containers/server/routes/WebHookController.ts @@ -0,0 +1,19 @@ +import {Logger} from 'winston'; + +import { + Controller, RouteParamBody, RoutePost, +} from './Controller.ts'; + +export class WebHookController extends Controller { + + constructor(subPath: string, private readonly queryLogger: Logger) { + super(subPath); + } + + @RoutePost('/') + async postEvent(@RouteParamBody() body: undefined) { + this.queryLogger.info(`WebHookController.postEvent ${JSON.stringify(body)}`); + + return {}; + } +}