Add support for webhook endpoints

This commit is contained in:
KernelDeimos 2024-05-21 17:25:28 -04:00
parent cc45a08388
commit 90463a0732
3 changed files with 12 additions and 4 deletions

View File

@ -51,7 +51,7 @@ class BaseService extends AdvancedBase {
async __on (id, args) {
const handler = this.__get_event_handler(id);
return await handler(id, args);
return await handler(id, ...args);
}
__get_event_handler (id) {

View File

@ -113,7 +113,7 @@ class Container {
const promises = [];
for ( const k in this.instances_ ) {
if ( this.instances_[k].__on ) {
promises.push(this.instances_[k].__on(id, ...args));
promises.push(this.instances_[k].__on(id, args));
}
}
await Promise.all(promises);

View File

@ -46,7 +46,10 @@ class WebServerService extends BaseService {
const app = this.app;
const services = this.services;
await services.emit('install.middlewares.context-aware', { app });
await services.emit('install.routes', { app });
await services.emit('install.routes', {
app,
router_webhooks: this.router_webhooks,
});
await services.emit('install.routes-gui', { app });
}
@ -123,7 +126,7 @@ class WebServerService extends BaseService {
ports_to_try = null; // GC
const url = config.origin;
this.startup_widget = () => {
const link = `\x1B[34;1m${osclink(url)}\x1B[0m`;
const lines = [
@ -320,6 +323,11 @@ class WebServerService extends BaseService {
}
})
// Web hooks need a router that occurs before JSON parse middleware
// so that signatures of the raw JSON can be verified
this.router_webhooks = express.Router();
app.use(this.router_webhooks);
app.use(express.json({limit: '50mb'}));
const cookieParser = require('cookie-parser');