Skip to content

Commit

Permalink
fix: pass res.locals to HttpIncoming constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalsadhu committed Apr 11, 2024
1 parent b9ef277 commit f9b6336
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
5 changes: 1 addition & 4 deletions lib/podlet.js
Original file line number Diff line number Diff line change
Expand Up @@ -903,10 +903,7 @@ export default class PodiumPodlet {
*/
middleware() {
return async (req, res, next) => {
// initialise res.locals.params so that it can be added to anywhere including in route hooks
// or middleware added after this middleware
res.locals.params = res.locals.params || {};
const incoming = new HttpIncoming(req, res, res.locals.params);
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
7 changes: 5 additions & 2 deletions 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 @@ -1310,7 +1312,8 @@ tap.test('.view() - append a custom wireframe document - should render developme
podlet.view((incoming, data) => `<div data-foo="${incoming.params.foo}">${data}</div>`);

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

Expand Down

0 comments on commit f9b6336

Please sign in to comment.