Load a remote configuration
Use this procedure to get the settings from a server. The server can change the settings for all visitors.
Procedure
Put a configuration document on your server, for example at
/api/wand.json.Make sure that the document has the format
{ "v": 1, "<section>": { ... } }.Import
httpProviderfrommagic-cursor-wand/providers.Add the provider to the
providersoption:tsimport { createWand } from 'magic-cursor-wand'; import { httpProvider, localStorageProvider } from 'magic-cursor-wand/providers'; const wand = createWand({ providers: [ httpProvider({ url: '/api/wand.json', headers: { Accept: 'application/json' }, pollMs: 60_000, }), localStorageProvider({ key: 'my-site-wand' }), ], startAfter: 'ready', });Open the page. Make sure that the effects use the values from the server.
Result
The provider sends one GET request when the wand starts. If you set pollMs, the provider sends a request again at this interval. It uses ETag and If-None-Match, so an unchanged document costs a small response only.
In the example, startAfter: 'ready' delays the first frame until the providers settle. To wait for the providers in your own code, use wand.ready:
await wand.ready;To let the page save to the server, set save: 'PUT' or save: 'POST'.