Skip to content

Commit

Permalink
Merge pull request #1392 from opencomponents/action-endpoint
Browse files Browse the repository at this point in the history
add actions endpoint
  • Loading branch information
ricardo-devis-agullo authored Feb 9, 2025
2 parents c669a24 + 18f08fe commit 5cd3a46
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/registry/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.post(
`${prefix}~actions/:action/:componentName/:componentVersion`,
routes.component
);
app.post(`${prefix}~actions/:action/:componentName`, routes.component);

if (conf.routes) {
for (const route of conf.routes) {
app[
Expand Down
11 changes: 10 additions & 1 deletion src/registry/routes/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>;
if (req.method === 'POST') {
parameters = {
...parameters,
...(req.body as Record<string, string>)
};
}

getComponent(
{
action: req.params['action'],
conf: res.conf,
headers: req.headers,
ip: req.ip!,
name: req.params['componentName'],
parameters: req.query as Record<string, string>,
parameters,
version: req.params['componentVersion']
},
(result) => {
Expand Down
2 changes: 1 addition & 1 deletion src/registry/routes/helpers/get-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 5cd3a46

Please sign in to comment.