-
-
Notifications
You must be signed in to change notification settings - Fork 807
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Dynamic service providers and arguments #844
Comments
I would suggest using (prefixed) environmental flags if you just want basic bootstrapping. For example imagine you have two providers: Foo and Bar. const enabledServices = process.env.OSJS_SERVICES.split(',')
if (enabledServices.includes('Foo')) {
osjs.register(FooServiceProvider, {
args: {
arg1: process.env.OSJS_SERVICE_FOO_ARG1,
arg2: process.env.OSJS_SERVICE_FOO_ARG2,
}
})
}
if (enabledServices.includes('Bar')) {
osjs.register(BarServiceProvicer, {
args: {
arg1: process.env.OSJS_SERVICE_BAR_ARG1,
arg2: process.env.OSJS_SERVICE_BAR_ARG2,
}
})
} Then this could be set up with:
If you need something more advanced, use something like a JSON file that you bind via a [ro] volume and just read that in your bootstrap file and do whatever you need. This can then be copied into an image in your Dockerfile or whatever for deployments. |
Just a note on dynamically registering service providers and behaviour on runtime. To make sure things don't crash whenever a service provider has not been registered and you perform
|
And I just had a thought. You can actually set up the client-side providers via the backend so you don't have to compile to apply settings from the environment.
// Your server provider
class MyServiceProvider {
constructor(core, options = {}) {
this.core = core;
this.options = options;
}
async init() {
const {route} = this.core.make('osjs/express');
route('GET', '/my-endpoint', (req, res) => {
res.json({ services: ['Foo', 'Bar'] });
});
}
} // Your client bootstrap
async function init() {
const myConfiguration = await osjs.request('/my-endpoint');
// ... register stuff
// --> myConfiguration.services
} |
Thank you for your complete explanation <3 |
You're very welcome! I designed the Service (Provider) API to be able to handle this, and my examples should be enough to get you started with implementing this, so I'll close this issue. If it doesn't work out or you have any additional questions feel free to re-open 😄 |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
hi @andersevenrud
In your opinion, how can I control the registration of adapters and service providers through the
docker-compose.yml
file?The text was updated successfully, but these errors were encountered: