Skip to content

Commit

Permalink
Merge pull request #382 from podium-lib/pass_params_to_http_incoming
Browse files Browse the repository at this point in the history
Pass params to http incoming
  • Loading branch information
digitalsadhu authored Apr 14, 2024
2 parents f2db5d6 + 1e758be commit 2b37340
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/podlet.js
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ export default class PodiumPodlet {
*/
middleware() {
return async (req, res, next) => {
const incoming = new HttpIncoming(req, res);
const incoming = new HttpIncoming(req, res, res.locals);
// @ts-ignore
incoming.url = new URL(
req.originalUrl,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"eslint-plugin-import": "2.29.1",
"eslint-plugin-prettier": "5.1.3",
"express": "4.19.2",
"json-stringify-safe": "5.0.1",
"prettier": "3.2.4",
"semantic-release": "23.0.6",
"tap": "18.7.2",
Expand Down
22 changes: 21 additions & 1 deletion tests/podlet.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// @ts-nocheck

/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable no-unused-expressions */
/* eslint-disable max-classes-per-file */
/* eslint-disable no-param-reassign */

import { destinationObjectStream } from '@podium/test-utils';
import { template, HttpIncoming, AssetJs, AssetCss } from '@podium/utils';
import stringify from 'json-stringify-safe';
import { join, dirname } from 'path';
import Metrics from '@metrics/client';
import tap from 'tap';
Expand Down Expand Up @@ -120,7 +122,7 @@ class FakeExpressServer {
this.app.use(
onRequest ||
((req, res) => {
res.status(200).json(res.locals);
res.status(200).send(stringify(res.locals));
}),
);
this.server = undefined;
Expand Down Expand Up @@ -1303,6 +1305,24 @@ tap.test('.view() - append a custom wireframe document - should render developme
await server.close();
});

tap.test('.view() - append a custom wireframe document - should render development output with custom wireframe document', async (t) => {
const options = { ...DEFAULT_OPTIONS, development: true };

const podlet = new Podlet(options);
podlet.view((incoming, data) => `<div data-foo="${incoming.params.foo}">${data}</div>`);

const server = new FakeExpressServer(podlet, (req, res) => {
res.locals.foo = 'bar';
res.podiumSend('<h1>OK!</h1>');
});

await server.listen();
const result = await server.get({ raw: true });

t.equal(result.response, '<div data-foo="bar"><h1>OK!</h1></div>');
await server.close();
});

// #############################################
// .metrics()
// #############################################
Expand Down

0 comments on commit 2b37340

Please sign in to comment.