diff --git a/sample/init.js b/sample/init.js new file mode 100644 index 00000000..f4f7971d --- /dev/null +++ b/sample/init.js @@ -0,0 +1,17 @@ +// this is called from the `app.js` function `initModule()` around line `200` +// from there you can get the structure passed in the "server" object +// which includes and `api` and other helper functions + +module.exports = function(server) { + +server.util.log("--- sample server-side module installed ---"); + +// insert script after all others in kiri browser code +server.inject("kiri", "kiri.js", {end: true}); + +server.onload(() => { + server.util.log("--- called after all modules loaded ---"); +}); + + +}; diff --git a/sample/kiri.js b/sample/kiri.js new file mode 100644 index 00000000..18a31d66 --- /dev/null +++ b/sample/kiri.js @@ -0,0 +1,6 @@ +console.log('--- in the browser main loop ---'); + +// the kiri api starts around line `260` of `src/kiri/main.js` +kiri.load(function(api) { + console.log('--- kiri startup complete ---'); +}); diff --git a/sample/readme.md b/sample/readme.md new file mode 100644 index 00000000..57866b9f --- /dev/null +++ b/sample/readme.md @@ -0,0 +1,16 @@ +# Application modules + +This allows for the loading of server-side modules which can, in turn, +inject browser modules into applications like Kiri:Moto. + +To enable the sample module: + +* create a `mod` directory at the root of grid-apps +* copy the sample directory into the mod directory: `mod/sample` +* (re)start `gs-app-server` +* you will see log lines at start-up similar to this + +``` +220128.120432 '[head]' { module: './mod/sample/init.js' } +220128.120432 '[head]' '--- sample server-side module loaded ---' +```