Skip to content

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

Merged
oscar-ekeyekwu merged 7 commits into
microapidev:v2from
dave-ok:ft-settings-middleware
Aug 7, 2020
Merged

PR - [feature]: Add middlware to retrieve settings#540
oscar-ekeyekwu merged 7 commits into
microapidev:v2from
dave-ok:ft-settings-middleware

Conversation

@dave-ok
Copy link
Copy Markdown
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
Copy Markdown
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