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

Feature/dynamic config load #1981

Merged
merged 6 commits into from
Nov 10, 2018

Conversation

CodeSkills
Copy link
Collaborator

Related issues

None

Short description and why it's useful

This enables to load dynamic config on every page load.

Anyone can simply define loadConfig function within src/server/index.js that returns a Promise.

module.exports.loadConfig = (req) => {
  const axios = require('axios')
   return new Promise((resolve, reject) => axios.get('myapi.com/config', {
     params: {
       domain: req.headers.host
     }
   }).then(res => {
    resolve(res.data)
   }).catch(error => reject(error)))
 }

Screenshots of visual changes before/after (if there are any)

None

Screenshot of passed e2e tests (if you are using our standard setup as a backend)

Using own API - tested locally (debug and visual)

Upgrade Notes and Changelog

  • No upgrade steps required (100% backward compatibility)
  • I've updated the Upgrade notes and Changelog on how to port existing VS sites with this new feature

Contribution and currently important rules acceptance

@filrak
Copy link
Collaborator

filrak commented Nov 10, 2018

With this approach is keeping config in apps state still necessary? @pkarw wdyt?

Copy link
Collaborator

@pkarw pkarw left a comment

Choose a reason for hiding this comment

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

It’s a cool feature! Thanks a lot! Can You also add some docs on that?

@NataliaTepluhina could you please add these docs to the official resources?

core/modules/user/store/actions.ts Show resolved Hide resolved
core/scripts/server.js Outdated Show resolved Hide resolved
@pkarw
Copy link
Collaborator

pkarw commented Nov 10, 2018

@filrak yes, it’s bascially the only way to provide the config to CSR - we need config to properly execute client side code. Ofc we can do separate request just for config from Clients side but it makes no sense; it’s more optimal to keep it in state in this case.

When user doesn’t require to have dynamic config reload then config is not provided to the clients side but just compiled into webpack bundle

@CodeSkills
Copy link
Collaborator Author

@pkarw Renamed the function and added basic Docs to the end of Config Docs.

@pkarw
Copy link
Collaborator

pkarw commented Nov 10, 2018

Awesome, Thanks! Will merge it once get in front of my computer :)

@CodeSkills
Copy link
Collaborator Author

Last thing, when the Promise is rejected (for some reason which could happen). There should be 2 options

  1. Continue with default (build time/runtime config)
  2. Throw Error 500 page

These are rare occurrences but will eventually happen.

@pkarw Should I add a config for dynamicConfigReload that can decide between these two?

@pkarw
Copy link
Collaborator

pkarw commented Nov 10, 2018

Yes Please, thats a good point. We should have the option in config for that 👍

@CodeSkills
Copy link
Collaborator Author

CodeSkills commented Nov 10, 2018

Added the option and tested all options with latest changes to check that all works as expected.

@pkarw Let me know if you come up with better naming for the option :-)

It now allows to configure an option if it should continue with built time config or to be redirected to /error page.

@pkarw
Copy link
Collaborator

pkarw commented Nov 10, 2018

Perfect. Thanks!

@pkarw pkarw merged commit 7ab0f93 into vuestorefront:develop Nov 10, 2018
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.

None yet

3 participants