Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor express.json middleware to be route explicit #210

Merged
merged 2 commits into from
Sep 14, 2023

Conversation

jujaga
Copy link
Member

@jujaga jujaga commented Sep 14, 2023

Description

The express-unless library ended up being a cognitive risk to easily understanding when a json body needs to be parsed and under which routes and conditions. By modifying our router logic to only execute express.json() when the endpoint really needs it, we can avoid this problem and improve code intent and clarity.
Json parsing for arguments also do not require a body larger than the default library length of 100kb, so we are removing the configuration option entirely.

Types of changes

Bug fix (non-breaking change which fixes an issue)

Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the CONTRIBUTING doc
  • I have checked that unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

In our case, json parsing for arguments do not require a body larger than
the default library length of 100kb, so we are removing the configuration
option entirely.

Signed-off-by: Jeremy Ho <[email protected]>
The express-unless library ended up being a cognitive risk to easily
understanding when a json body needs to be parsed and under which routes
and conditions. By modifying our router logic to only execute
express.json() when the endpoint really needs it, we can avoid this
problem and improve code intent and clarity.

Signed-off-by: Jeremy Ho <[email protected]>
@jujaga jujaga added bug Something isn't working dependencies Pull requests that update a dependency file labels Sep 14, 2023
@jujaga jujaga requested a review from norrisng-bc as a code owner September 14, 2023 19:36
@jujaga jujaga self-assigned this Sep 14, 2023
@jujaga jujaga requested a review from TimCsaky as a code owner September 14, 2023 19:36
@codeclimate
Copy link

codeclimate bot commented Sep 14, 2023

Code Climate has analyzed commit 806f7fc and detected 2 issues on this pull request.

Here's the issue category breakdown:

Category Count
Duplication 2

The test coverage on the diff in this pull request is 100.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 58.7% (0.1% change).

View more on Code Climate.

@github-actions
Copy link

Coverage Report

Totals Coverage
Statements: 52.48% ( 2469 / 4705 )
Methods: 42.54% ( 268 / 630 )
Lines: 58.72% ( 1499 / 2553 )
Branches: 46.12% ( 702 / 1522 )

@TimCsaky TimCsaky merged commit fcf706c into master Sep 14, 2023
12 checks passed
@TimCsaky TimCsaky deleted the bugfix/explicitjsonparsing branch September 14, 2023 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies Pull requests that update a dependency file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants