From 6ff9ba8f8c634d537b0a0b357b082af0ec283f96 Mon Sep 17 00:00:00 2001 From: Ricardo Devis Agullo Date: Sat, 8 Feb 2025 13:04:42 +0100 Subject: [PATCH 1/2] add actions endpoint --- src/registry/router.ts | 6 ++++++ src/registry/routes/component.ts | 11 ++++++++++- src/registry/routes/helpers/get-component.ts | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/registry/router.ts b/src/registry/router.ts index e26ac25d8..d6b048cf0 100644 --- a/src/registry/router.ts +++ b/src/registry/router.ts @@ -76,6 +76,12 @@ export function create(app: Express, conf: Config, repository: Repository) { app.get(`${prefix}:componentName/:componentVersion`, routes.component); app.get(`${prefix}:componentName`, routes.component); + app.get( + `${prefix}~actions/:action/:componentName/:componentVersion`, + routes.component + ); + app.get(`${prefix}~actions/:action/:componentName`, routes.component); + if (conf.routes) { for (const route of conf.routes) { app[ diff --git a/src/registry/routes/component.ts b/src/registry/routes/component.ts index b45d0b8c5..9faa558ba 100644 --- a/src/registry/routes/component.ts +++ b/src/registry/routes/component.ts @@ -13,13 +13,22 @@ export default function component( const getComponent = GetComponentHelper(conf, repository); return (req: Request, res: Response): void => { + let parameters = req.query as Record; + if (req.method === 'POST') { + parameters = { + ...parameters, + ...(req.body as Record) + }; + } + getComponent( { + action: req.params['action'], conf: res.conf, headers: req.headers, ip: req.ip!, name: req.params['componentName'], - parameters: req.query as Record, + parameters, version: req.params['componentVersion'] }, (result) => { diff --git a/src/registry/routes/helpers/get-component.ts b/src/registry/routes/helpers/get-component.ts index 16baaaf99..791be2922 100644 --- a/src/registry/routes/helpers/get-component.ts +++ b/src/registry/routes/helpers/get-component.ts @@ -277,7 +277,7 @@ export default function getComponent(conf: Config, repository: Repository) { supportedTemplates.includes(templateType)) ); - let renderMode = 'rendered'; + let renderMode = options.action ? 'unrendered' : 'rendered'; if (isUnrendered) { renderMode = 'unrendered'; if ( From 18f08fe681ef99bbc22411ac2e9d08d72e4bebd8 Mon Sep 17 00:00:00 2001 From: Ricardo Devis Agullo Date: Sun, 9 Feb 2025 11:50:04 +0100 Subject: [PATCH 2/2] transform to post --- src/registry/router.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/registry/router.ts b/src/registry/router.ts index d6b048cf0..c28b2347a 100644 --- a/src/registry/router.ts +++ b/src/registry/router.ts @@ -76,11 +76,11 @@ export function create(app: Express, conf: Config, repository: Repository) { app.get(`${prefix}:componentName/:componentVersion`, routes.component); app.get(`${prefix}:componentName`, routes.component); - app.get( + app.post( `${prefix}~actions/:action/:componentName/:componentVersion`, routes.component ); - app.get(`${prefix}~actions/:action/:componentName`, routes.component); + app.post(`${prefix}~actions/:action/:componentName`, routes.component); if (conf.routes) { for (const route of conf.routes) {