mirror of
https://github.com/gnh1201/welsonjs.git
synced 2024-11-26 15:31:42 +00:00
Update defaultService.example.js
This commit is contained in:
parent
6eaeab5c24
commit
e1d4df74b9
|
@ -2,8 +2,14 @@
|
||||||
// https://github.com/gnh1201/welsonjs
|
// https://github.com/gnh1201/welsonjs
|
||||||
var SYS = require("lib/system");
|
var SYS = require("lib/system");
|
||||||
|
|
||||||
// env
|
// Examples of class (prototype) and instance referencing .env values
|
||||||
var env = {};
|
function examplePrototype() {
|
||||||
|
this.env = {};
|
||||||
|
this.setEnv = function(k, v) {
|
||||||
|
this.env[k] = v;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
var exampleInstance = new examplePrototype();
|
||||||
|
|
||||||
function main(args) {
|
function main(args) {
|
||||||
console.log("WelsonJS.Service required.");
|
console.log("WelsonJS.Service required.");
|
||||||
|
@ -16,12 +22,14 @@ function getDeviceID() {
|
||||||
function onServiceStart(args) {
|
function onServiceStart(args) {
|
||||||
// load the environment file
|
// load the environment file
|
||||||
FILE.loadEnvFromArgs(args, function(envConfig) {
|
FILE.loadEnvFromArgs(args, function(envConfig) {
|
||||||
if ("message" in envConfig) {
|
// In Node.js and recent JavaScript engines, it is common to assign .env values globally, such as with `process.env`.
|
||||||
env.message = envConfig.message;
|
// However, WelsonJS is designed to limit the scope to specific areas.
|
||||||
|
for (var envKey in envConfig) {
|
||||||
|
exampleInstance.setEnv(envKey, envConfig[envKey]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return "onServiceStart recevied. " + args.join(', ') + ", env: " + JSON.stringify(env);
|
return "onServiceStart recevied. " + args.join(', ') + ", env: " + JSON.stringify(exampleInstance.env);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onServiceStop() {
|
function onServiceStop() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user