diff --git a/results-tabulation-ui/.env b/results-tabulation-ui/.env new file mode 100644 index 00000000..77aac1c8 --- /dev/null +++ b/results-tabulation-ui/.env @@ -0,0 +1,5 @@ +REACT_APP_AUTH_APP_URL='http://localhost:3001' +REACT_APP_TABULATION_API_URL='http://localhost:5000' +REACT_APP_DEBUG=false +REACT_APP_TABULATION_API_PAGINATION_LIMIT=3 +REACT_APP_USE_PDF_SERVICE=false diff --git a/results-tabulation-ui/Dockerfile b/results-tabulation-ui/Dockerfile index 7732aa30..d5ddbe80 100644 --- a/results-tabulation-ui/Dockerfile +++ b/results-tabulation-ui/Dockerfile @@ -9,7 +9,8 @@ RUN npm install ENV REACT_APP_AUTH_APP_URL="https://tabulations.ecdev.opensource.lk" ENV REACT_APP_TABULATION_API_URL="https://apim-gateway.ecdev.opensource.lk/tabulation/0.1.0" ENV REACT_APP_DEBUG=true -ENV TABULATION_API_PAGINATION_LIMIT=250 +ENV REACT_APP_TABULATION_API_PAGINATION_LIMIT=250 +ENV REACT_APP_USE_PDF_SERVICE=true RUN npm run build diff --git a/results-tabulation-ui/Stage.Dockerfile b/results-tabulation-ui/Stage.Dockerfile index 0b18868d..833d891b 100644 --- a/results-tabulation-ui/Stage.Dockerfile +++ b/results-tabulation-ui/Stage.Dockerfile @@ -8,7 +8,9 @@ RUN npm install ENV REACT_APP_AUTH_APP_URL="https://tabulations.ecstage.opensource.lk" ENV REACT_APP_TABULATION_API_URL="https://apim-gw.ecstage.opensource.lk/tabulation/0.1.0" -ENV TABULATION_API_PAGINATION_LIMIT=250 +ENV REACT_APP_DEBUG=false +ENV REACT_APP_TABULATION_API_PAGINATION_LIMIT=250 +ENV REACT_APP_USE_PDF_SERVICE=true RUN npm run build diff --git a/results-tabulation-ui/Staging.Dockerfile b/results-tabulation-ui/Staging.Dockerfile index 74316812..ac890db6 100644 --- a/results-tabulation-ui/Staging.Dockerfile +++ b/results-tabulation-ui/Staging.Dockerfile @@ -8,7 +8,9 @@ RUN npm install ENV REACT_APP_AUTH_APP_URL="https://tabulations.ecstag.opensource.lk" ENV REACT_APP_TABULATION_API_URL="https://apim-gw.ecstag.opensource.lk/tabulation/0.1.0" -ENV TABULATION_API_PAGINATION_LIMIT=250 +ENV REACT_APP_DEBUG=false +ENV REACT_APP_TABULATION_API_PAGINATION_LIMIT=250 +ENV REACT_APP_USE_PDF_SERVICE=true RUN npm run build diff --git a/results-tabulation-ui/prod.Dockerfile b/results-tabulation-ui/prod.Dockerfile index 4374b465..6d514c05 100644 --- a/results-tabulation-ui/prod.Dockerfile +++ b/results-tabulation-ui/prod.Dockerfile @@ -8,7 +8,9 @@ RUN npm install ENV REACT_APP_AUTH_APP_URL="https://tabulations-lgc.elections.gov.lk" ENV REACT_APP_TABULATION_API_URL="https://apim-gw-lgc.elections.gov.lk/tabulation/0.1.0" -ENV TABULATION_API_PAGINATION_LIMIT=250 +ENV REACT_APP_DEBUG=false +ENV REACT_APP_TABULATION_API_PAGINATION_LIMIT=250 +ENV REACT_APP_USE_PDF_SERVICE=true RUN npm run build diff --git a/results-tabulation-ui/src/config.js b/results-tabulation-ui/src/config.js index ed0476a3..36adf44a 100644 --- a/results-tabulation-ui/src/config.js +++ b/results-tabulation-ui/src/config.js @@ -13,13 +13,45 @@ if (process.env.REACT_APP_TABULATION_API_URL) { } if (process.env.REACT_APP_DEBUG) { - DEBUG = process.env.REACT_APP_DEBUG; + DEBUG = getBooleanEnvVar(process.env.REACT_APP_DEBUG, DEBUG); } -if (process.env.TABULATION_API_PAGINATION_LIMIT) { - TABULATION_API_PAGINATION_LIMIT = process.env.TABULATION_API_PAGINATION_LIMIT; +if (process.env.REACT_APP_TABULATION_API_PAGINATION_LIMIT) { + TABULATION_API_PAGINATION_LIMIT = getIntEnvVar(process.env.REACT_APP_TABULATION_API_PAGINATION_LIMIT, TABULATION_API_PAGINATION_LIMIT); } -if (process.env.USE_PDF_SERVICE) { - USE_PDF_SERVICE = process.env.USE_PDF_SERVICE; +if (process.env.REACT_APP_USE_PDF_SERVICE) { + USE_PDF_SERVICE = getBooleanEnvVar(process.env.REACT_APP_USE_PDF_SERVICE, USE_PDF_SERVICE); +} + +function getBooleanEnvVar(envVar, defaultValue) { + if (envVar) { + envVar = envVar.toLowerCase(); + if (envVar === "true") { + envVar = true; + } else if (envVar === "false") { + envVar = false; + } else { + envVar = defaultValue; + } + } else { + envVar = defaultValue; + } + + return envVar; +} + + +function getIntEnvVar(envVar, defaultValue) { + if (envVar) { + try { + envVar = parseInt(envVar); + } catch (e) { + envVar = defaultValue; + } + } else { + envVar = defaultValue; + } + + return envVar; }