Skip to content

Commit

Permalink
adjust cookie parser invocation to earlier in the lifecycle chain (#1009
Browse files Browse the repository at this point in the history
)

* adjust cookie parser invocation to earlier in the lifecycle chain

* CHANGELOG
  • Loading branch information
mmason2-godaddy authored Jan 13, 2025
1 parent ee81693 commit e71aa0f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/gasket-plugin-express/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# `@gasket/plugin-express`

- adjust cookie parser invocation to earlier in the lifecycle chain ([#1009])

### 7.1.1

- Ensure cookies are parsed ([#1001])
Expand Down Expand Up @@ -146,3 +148,4 @@
[#959]: https://github.com/godaddy/gasket/pull/959
[#969]: https://github.com/godaddy/gasket/pull/969
[#1001]: https://github.com/godaddy/gasket/pull/1001
[#1009]: https://github.com/godaddy/gasket/pull/1009
1 change: 0 additions & 1 deletion packages/gasket-plugin-express/lib/create-servers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/
module.exports = async function createServers(gasket, serverOpts) {
const app = gasket.actions.getExpressApp();
app.use(require('cookie-parser')());

await gasket.exec('express', app);

Expand Down
11 changes: 10 additions & 1 deletion packages/gasket-plugin-express/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@ const plugin = {
getExpressApp(gasket) {
const express = require('express');
const { http2 } = gasket.config;
app ??= http2 ? require('http2-express')(express) : express();

if (!app) {
if (http2) {
app = require('http2-express')(express);
} else {
app = express();
}

app.use(require('cookie-parser')());
}

return app;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/gasket-plugin-express/test/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('createServers', () => {
});

it('attaches cookie parser middleware', async function () {
await plugin.hooks.createServers(gasket, {});
plugin.actions.getExpressApp(gasket);
expect(app.use).toHaveBeenCalledWith(cookieParserMiddleware);
});

Expand Down

0 comments on commit e71aa0f

Please sign in to comment.