podium-lib / issues

All podium issues, bugs, questions etc goes here. Documentation is to be found at https://podium-lib.io
1 stars 0 forks source link

incoming.podlets should handle a single podlet response #30

Closed alexanbj closed 2 years ago

alexanbj commented 4 years ago

If you use the default document template in @podium/layout to handle podlet assets, you should be able to handle multiple podlets and a single podlet in same way.

There is a incoming.podlets property which sets the JS and CSS accordingly, but it only supports an array of podlet responses. So for a single podlet you'll have to set .css and .js.

app.get('/', async (req, res) => {
  const incoming = res.locals.podium;

  // If we have a single podlet
  const result = await podlet.fetch(incoming);
  incoming.js = result.js;
  incoming.css = result.css;

  res.podiumSend(result.content);

  // If we have multiple podlets
  const responses = await Promise.all([podlet1.fetch(incoming), podlet2.fetch(incoming)];
  incoming.podlets = responses;

  res.podiumSend(responses[0].content + responses[1].content);

});

We should change incoming.podlets so it also handles a single podlet response, not just an array.