nodefony
Version:
Nodefony Framework Core
134 lines (127 loc) • 3.45 kB
JavaScript
/**
* ENTRY POINT FRAMEWORK APP KERNEL
*/
"use strict;";
const blue = clc.blueBright.bold;
const green = clc.green;
const yellow = clc.yellow.bold;
const magenta = clc.magenta.bold;
const reset = clc.reset; // '\x1b[0m';
module.exports = class appKernel extends nodefony.kernel {
constructor(environment, cli, settings) {
// kernel constructor
super(environment, cli, settings);
this.appEnvironment = this.getAppEnvironment()
if (this.appEnvironment.environment === 'development') {
this.once("onPreRegister", () => {
/*if (this.type === "SERVER") {
return this.showBanner()
}*/
})
}
{% if addons.workbox %}
this.on("onServeStatic", (res, path, name) => {
if (name === "web" && path.match(/.*service-worker.js$/)){
res.setHeader('Service-Worker-Allowed', '/');
}
});
{% endif %}
}
showBanner() {
let banner = `App Environment`
for (let ele in this.appEnvironment) {
let module = this.appEnvironment[ele]
switch (ele) {
case "environment":
banner = ` ${magenta(" Environement")} : ${green(module)}`;
console.log(banner)
this.cli.blankLine();
break;
case "vault":
banner = `Module : ${green(ele)} Vault : ${blue(module.active)}`;
this.log(banner);
break
default:
banner = `Module : ${green(ele)} `;
if (module.vault) {
banner += `Vault : ${blue(module.vault.active)}`
}
this.log(banner);
}
}
this.cli.blankLine();
}
getAppEnvironment() {
const environment = this.getVariableEnvironment()
return {
environment: environment,
database: this.getDatabaseEnvironment(environment),
vault: this.getVaultEnvironment(environment)
}
}
getVariableEnvironment() {
if (process.env.NODEFONY_ENV_APP) {
return process.env.NODEFONY_ENV_APP
}
const production = process.env.NODE_ENV === "production"
const development = process.env.NODE_ENV === "development"
if (production) {
return 'production'
}
if (development) {
return 'development'
}
return 'development'
}
/* VAULT BUNDLE */
getVaultEnvironment(environment) {
switch (environment) {
case 'production':
return {
active: true,
prepareAuth: false,
getVaultCredentialsApprole: this.getVaultCredentialsApprole(environment)
}
case 'development':
default:
return {
active: true,
prepareAuth: true,
getVaultCredentialsApprole: this.getVaultCredentialsApprole(environment)
}
}
}
getDatabaseEnvironment(environment) {
switch (environment) {
case 'production':
return {
vault: {
active: true,
path: "nodefony/data/postgresql/connector/nodefony"
},
}
case 'development':
default:
return {
vault: {
active: false,
path: "nodefony/data/sqlite/connector/nodefony"
},
}
}
}
getVaultCredentialsApprole(environment) {
switch (environment) {
case 'production':
return async () => {
return {
role_id: "",
secret_id: ""
}
}
case 'development':
default:
return null
}
}
};