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

PR - [feature]: Add middlware to retrieve settings #540

Merged
merged 7 commits into from
Aug 7, 2020

Conversation

dave-ok
Copy link
Member

@dave-ok dave-ok commented Aug 7, 2020

PR Checklist

  • Run npm run lint to find errors in code syntax/format
  • Run npm run lint:fix to fix all auto-fixable errors in source code and auto-format with prettier
  • Ensure you fix any linting errors displayed after running any of the above commands

What does this PR do

Fixes #538

A middleware to retrieve remote settings on each request, parse and validate settings, and attach settings to request object, for availability down the middleware chain in the request/response cycle

Description of Task to be completed

  • Create settings parser
  • Add validation option to parser
  • Write tests for parser
  • Create middleware to
    • validate API key found on custom header x-microapi-projectkey,
    • decode projectID from API key signed with a shared secret,
    • retrieve settings for given projectID,
    • parse and validate returned settings
    • attach projectID and settings on request object
  • Write tests for middleware

How should this be manually tested

Run npm run test src/utils/__test__/settingsParser.test.js to test settings parser/validator
Run npm run test src/middleware/__test__/settings.test.js to test middleware

Any background context you want to provide

The settings middleware currently pulls mocked settings from a function in src/utils/mocks/settings which will be replaced by the actual settings provider when implemented

Copy link
Contributor

@oscar-ekeyekwu oscar-ekeyekwu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job bro

@oscar-ekeyekwu oscar-ekeyekwu merged commit ea09b9b into microapidev:v2 Aug 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE REQUEST] - Add settings middleware
2 participants