0

In my index.ts file I'm configuring my google recaptcha component with the sitekey:

Vue.use(VueReCaptcha, {
    siteKey: 'my_redacted_sitekey'
});

this happens before the new Vue({ ... }) statement.

I don't really want the siteKey hardcoded in the index.ts because we would have to redeploy it it would change.

Is there a way to outsource this value to a config file and use it here or is this not possible before the new Vue({}) statement?

Thanks in advance

1 Answer 1

1

You could place a config file in the /public folder and fetch it. (If you put it in /src it will be compiled.)

Simply fetch the config from any module including main.js at any time:

axios.get('config.json').then(response => {
  const json = response.data;
  // do something with the config
})

Ex. using axios

Remember to be mindful of site security as it's in the public folder this way.

There might be a temptation to load the Vue app inside the callback too, but this would cause a blank page until the file is loaded. It would be better to start the app with a loading message than to delay it with a blank page, for several reasons.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.