diff --git a/README.md b/README.md index 2455bad..f6ccce5 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ Another important point is NOT TO HAVE in backend db table user_Core (managed by This issue is related to the link between userCore and tblUser tables. - clone this repo (creates the `openimis-fe_js` directory) -- install node +- install node (node V16.x) - install yarn - within `openimis-fe_js` directory - generate the openIMIS modules dependencies and locales (from openimis.json config): `yarn load-config` or `yarn load-config openimis.json` @@ -267,3 +267,45 @@ Note: This image only provides the openimis frontend server. The full openIMIS d } ``` - this approach overwrites default `en` language translations into `en-gm` (Gambian English) translations without adding new language on database level and without changing 'locales' in 'openimis.json' and 'locales.js' file both on assembly frontend module (openimis-fe_js). + + +## Handling errors while running openIMIS app - the most common ones + +### Handling error with ` no content display` after running frontend +Based on error reported on that [ticket](https://openimis.atlassian.net/browse/OSD-176) + +Description of error: +* after `yarn start` the page loads but no content is display +* sometimes it just keeps spinning the loader +* web console doesn't show any errors + +How to solve this? +* double check if you use proper versions of backend/frontend modules (assembly and core ones) +* make sure you have the latest version of dockerized database + +Conclusions: +* The reason of this error is usually using not up-to-date assembly and core modules (both backend and frontend ones) + + +### Handling error with `400 error` after running frontend +Based on error reported on that [ticket](https://openimis.atlassian.net/browse/OSD-181) + +Description of error: +* modular openIMIS deployed on server +* backend is set on port 8000, frontend is set on port 3000 +* backend works fine, no errors +* it is not possible to reach both login and home page due to 400 error +* web console doesn't show any errors + +How to solve this? +* double check if you use proper versions of backend/frontend modules (assembly and core ones) +* make sure you added env variables on backend side (site root/sire url) +* double check value for `proxy` key in package.json (IMPORTANT: be careful with this setting on production environment) + +Conclusions: +* The reason of this error is usually not setting up env variables on backend side and wrong value for `proxy` key + + +### How to report another issues? +If you face another issues not described in that section you could use our [ticketing site](https://openimis.atlassian.net/servicedesk/customer/portal/1). +Here you can report any bugs/problems you faced during setting up openIMIS app. diff --git a/modules-config.js b/modules-config.js index d5e63e1..18d9aa7 100644 --- a/modules-config.js +++ b/modules-config.js @@ -1,85 +1,108 @@ -const fs = require('fs'); +const fs = require("fs"); +const pkg = require("./package.json"); function processLocales(config) { - var locales = fs.createWriteStream('./src/locales.js'); - let localeByLang = config['locales'].reduce( - (lcs, lc) => { - lc.languages.forEach((lg) => lcs[lg] = lc.intl); - return lcs - }, - {} - ); - let filesByLang = config['locales'].reduce( - (fls, lc) => { - lc.languages.forEach((lg) => fls[lg] = lc.fileNames); - return fls - }, - {} - ); - locales.write(`export const locales = ${JSON.stringify(config['locales'].map((lc) => lc.intl))}`); - locales.write(`\nexport const fileNamesByLang = ${JSON.stringify(filesByLang)}`); - locales.write(`/* eslint import/no-anonymous-default-export: [2, {"allowObject": true}] */`); - locales.write(`\nexport default ${JSON.stringify(localeByLang)}`); + var locales = fs.createWriteStream("./src/locales.js"); + let localeByLang = config["locales"].reduce((lcs, lc) => { + lc.languages.forEach((lg) => (lcs[lg] = lc.intl)); + return lcs; + }, {}); + let filesByLang = config["locales"].reduce((fls, lc) => { + lc.languages.forEach((lg) => (fls[lg] = lc.fileNames)); + return fls; + }, {}); + locales.write(`export const locales = ${JSON.stringify(config["locales"].map((lc) => lc.intl))}`); + locales.write(`\nexport const fileNamesByLang = ${JSON.stringify(filesByLang)}`); + locales.write(`/* eslint import/no-anonymous-default-export: [2, {"allowObject": true}] */`); + locales.write(`\nexport default ${JSON.stringify(localeByLang)}`); } -function getModuleLogicalName(module) { - return module.logicalName || module.npm.match(/([^/]*)\/([^@]*).*/)[2]; +function getConfig() { + // Try to get the configuration from the args + if (process.argv[2]) { + console.log(` load configuration from '${process.argv[2]}'`); + return JSON.parse(fs.readFileSync(process.argv[2], "utf-8")); + } else if (process.env.OPENIMIS_CONF_JSON) { + console.log(` load configuration from env`); + return JSON.parse(process.env.OPENIMIS_CONF_JSON); + } else if (fs.existsSync("./openimis.json")) { + console.log(` load configuration from ./openimis.json`); + return JSON.parse(fs.readFileSync("./openimis.json", "utf-8")); + } else { + throw new Error( + "No configuration file found. Please provide a configuration in the CLI or in the OPENIMIS_CONF_JSON environment variable", + ); + } } -function processModules(config, packageConfig) { - var srcModules = fs.createWriteStream('./src/modules.js'); - config['modules'].forEach((module) => { - let lib = module.npm.substring(0, module.npm.lastIndexOf('@')); - let version = module.npm.substring( module.npm.lastIndexOf('@')+1); - srcModules.write(`import { ${module.name} } from '${lib}';\n`); - packageConfig.dependencies[lib] = version; - }); - srcModules.write("\nexport const versions = [\n\t"); - srcModules.write(config["modules"].map((module) => `"${module.npm}"`).join(",\n\t")); - srcModules.write("\n];\nexport const modules = (cfg) => [\n\t"); - srcModules.write( - config["modules"] - .map((module) => `${module.name}((cfg && cfg["${getModuleLogicalName(module)}"]) || {})`) - .join(",\n\t") - ); - srcModules.write("\n];"); - srcModules.end(); - return packageConfig; +function processModules(modules) { + const stream = fs.createWriteStream("./src/modules.js"); -} + stream.write(` +export const packages = [ + ${modules.map(({ moduleName }) => `"${moduleName}"`).join(",\n ")} +];\n +`); -function applyConfig(config, packageConfig) { - processLocales(config); - packageConfig = processModules(config, packageConfig); + stream.write(` +export function loadModules (cfg = {}) { + return [ + ${modules + .map( + ({ name, logicalName, moduleName }) => + `require("${moduleName}").${name ?? "default"}(cfg["${logicalName}"] || {})`, + ) + .join(",\n ")} + ];\n } -// Configuration load +`); -function cleanDeps(packageConfig){ - for (const key in packageConfig.dependencies) { - if (key.startsWith('@openimis')) delete packageConfig.dependencies[key]; - } - return packageConfig; + stream.end(); } -fs.readFile('package.json', 'utf8', function read(err, data) { - if (err) throw err; - let packageConfig = cleanDeps(JSON.parse(data)); - try { - if(!process.env.OPENIMIS_CONF_JSON)throw 'OPENIMIS_CONF_JSON not set !'; - JSON.parse(process.env.OPENIMIS_CONF_JSON); - applyConfig(JSON.parse(process.env.OPENIMIS_CONF_JSON), packageConfig); - } catch (e) { +function main() { + /* + Load openIMIS configuration. Configuration is taken from args if provided or from the environment variable + */ + + // Remove @openimis dependencies from package.json + console.log("Remove @openimis dependencies from package.json"); + for (const key in pkg.dependencies) { + if (key.startsWith("@openimis/")) { + // This only covers modules made from the openIMIS organization + console.log(` removed ${key}`); + delete pkg.dependencies[key]; + } + } + + // Get openIMIS configuration from args + console.log("Load configuration"); + const config = getConfig(); + + console.log("Process Locales"); + processLocales(config); + + console.log("Process Modules"); + const modules = []; + for (const module of config.modules) { + const { npm, name, logicalName } = module; + // Find version number + const moduleName = npm.substring(0, npm.lastIndexOf("@")); + if (npm.lastIndexOf("@") <= 0) { + throw new Error(` Module ${moduleName} has no version set.`); + } + const version = npm.substring(npm.lastIndexOf("@") + 1); + console.log(` added "${moduleName}": ${version}`); + pkg.dependencies[moduleName] = version; + modules.push({ + moduleName, + version, + name, + npm, + logicalName: logicalName || npm.match(/([^/]*)\/([^@]*).*/)[2], + }); + } + processModules(modules); +} - - var configFile = process.argv[2]; - if (configFile === null || configFile === '' | configFile === undefined){ - configFile = './openimis.json'; - } - console.log("Using file %s, Env variable OPENIMIS_CONF_JSON not valid: %s", configFile, process.env.OPENIMIS_CONF_JSON) - fs.readFile(configFile, 'utf8', function read(err, data) { - if (err) throw err; - config = JSON.parse(data); - applyConfig(config, packageConfig); - }); - } -}); +main(); diff --git a/openimis.json b/openimis.json index c23057b..bf84de6 100644 --- a/openimis.json +++ b/openimis.json @@ -1,110 +1,106 @@ { - "locales": [ - { - "languages": [ - "en", - "en-GB" - ], - "intl": "en-GB", - "fileNames": "en" - }, - { - "languages": [ - "fr", - "fr-FR" - ], - "intl": "fr-FR", - "fileNames": "fr" - } - ], - "modules": [ - { + "locales": [ + { + "languages": [ + "en", + "en-GB" + ], + "intl": "en-GB", + "fileNames": "en" + }, + { + "languages": [ + "fr", + "fr-FR" + ], + "intl": "fr-FR", + "fileNames": "fr" + } + ], + "modules": [ +{ "name": "CoreModule", - "npm": "@openimis/fe-core@>=1.4.0" + "npm": "@openimis/fe-core@>=1.5.0" }, - { +{ "name": "HomeModule", - "npm": "@openimis/fe-home@>=1.4.0" + "npm": "@openimis/fe-home@>=1.5.0" }, - { +{ "name": "LocationModule", "npm": "@openimis/fe-location@>=1.4.0" }, - { +{ "name": "InsureeModule", - "npm": "@openimis/fe-insuree@>=1.4.0" + "npm": "@openimis/fe-insuree@>=1.5.0" }, - { +{ "name": "MedicalModule", - "npm": "@openimis/fe-medical@>=1.4.0" + "npm": "@openimis/fe-medical@>=1.5.0" }, - { +{ "name": "MedicalPriceListModule", - "npm": "@openimis/fe-medical_pricelist@>=1.4.0" + "npm": "@openimis/fe-medical_pricelist@>=1.5.0" }, - { +{ "name": "ProductModule", - "npm": "@openimis/fe-product@>=1.4.0" + "npm": "@openimis/fe-product@>=1.5.0" }, - { +{ "name": "PolicyModule", - "npm": "@openimis/fe-policy@>=1.4.0" + "npm": "@openimis/fe-policy@>=1.5.0" }, - { +{ "name": "PayerModule", - "npm": "@openimis/fe-payer@>=1.4.0" + "npm": "@openimis/fe-payer@>=1.4.1" }, - { +{ "name": "ContributionModule", - "npm": "@openimis/fe-contribution@>=1.4.0" + "npm": "@openimis/fe-contribution@>=1.4.1" }, - { +{ "name": "PaymentModule", - "npm": "@openimis/fe-payment@>=1.4.0" + "npm": "@openimis/fe-payment@>=1.4.1" }, - { +{ "name": "ClaimModule", - "npm": "@openimis/fe-claim@>=1.4.0" + "npm": "@openimis/fe-claim@>=1.4.1" }, - { +{ "name": "ClaimBatchModule", - "npm": "@openimis/fe-claim_batch@>=1.4.0" + "npm": "@openimis/fe-claim_batch@>=1.4.1" }, - { +{ "name": "AdminModule", - "npm": "@openimis/fe-admin@>=1.4.0" + "npm": "@openimis/fe-admin@>=1.4.1" }, - { +{ "name": "ToolsModule", - "npm": "@openimis/fe-tools@>=1.4.0" + "npm": "@openimis/fe-tools@>=1.5.0" }, - { +{ "name": "ProfileModule", - "npm": "@openimis/fe-profile@>=1.4.0" + "npm": "@openimis/fe-profile@>=1.5.0" }, - { +{ "name": "CalculationModule", - "npm": "@openimis/fe-calculation@>=1.4.0" + "npm": "@openimis/fe-calculation@>=1.4.1" }, - { +{ "name": "PolicyHolderModule", - "npm": "@openimis/fe-policyholder@>=1.4.0" + "npm": "@openimis/fe-policyholder@>=1.4.1" }, - { +{ "name": "ContributionPlanModule", - "npm": "@openimis/fe-contribution_plan@>=1.4.0" + "npm": "@openimis/fe-contribution_plan@>=1.5.0" }, - { +{ "name": "ContractModule", - "npm": "@openimis/fe-contract@>=1.4.0" + "npm": "@openimis/fe-contract@>=1.4.1" }, - { - "name": "LanguageFrModule", - "npm": "@openimis/fe-language_fr@>=1.3.0" - }, - { - "name": "InvoiceModule", - "npm": "@openimis/fe-invoice@>=1.4.0" - } - ] +{ + "name": "InvoiceModule", + "npm": "@openimis/fe-invoice@>=1.4.1" + } + ] } diff --git a/public/favicon.ico b/public/favicon.ico index a4f1d2c..8e8ad51 100644 Binary files a/public/favicon.ico and b/public/favicon.ico differ