Comments (5)
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:
OSJS_SERVICES=Foo,Bar
OSJS_SERVICE_FOO_ARG1=Hello
OSJS_SERVICE_FOO_ARG2=World
OSJS_SERVICE_BAR_ARG1=Bye
OSJS_SERVICE_BAR_ARG2=World
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.
from os.js.
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 core.make('my-namespace/something')
calls, etc.:
- Define the provided calls in your
provides()
returned array, i.e.:return ['my-namespace/something']
- Do
if (core.has('my-namespace/something')) {}
wrapping where you do the actual calls
from os.js.
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.
- Create a provider on the server that sets up an endpoint that returns some kind of configuration object based on
process.env
like described in my first post - On the client bootstrap
init
function, do a HTTP call to the above endpoint - Now you can register anything like you want it
// 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
}
from os.js.
Thank you for your complete explanation <3
from os.js.
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 😄
from os.js.
Related Issues (20)
- Can't open files HOT 5
- unify with daedalOS? HOT 2
- PWA support for OS.js applications and framework HOT 7
- Add requirements in README.md HOT 1
- Some questions with contextmenu HOT 2
- VFS Capability detection, other extensions HOT 6
- Security consideration in OSjs HOT 4
- Use Notification in login osjs HOT 3
- Needed Interface for OSjs Search Engine HOT 21
- update npm lockfile version
- How to handle node_modules in production mode HOT 1
- new feature: synchronizes all system notifications with the browser notifications HOT 5
- add finnish HOT 5
- people are uploading virus and malwares in demo page HOT 1
- Crashing the osjs when uploading a file in osjs mountpoint HOT 3
- Remove clock widget in demo HOT 4
- Failure to cancel file upload correctly HOT 1
- test route in osjs/express HOT 27
- The latest version of Node compatible with Osjs HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from os.js.