Skip to content

Commit

Permalink
update node for sass, fix #248 and config Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
pengyin-shan committed Jan 25, 2024
1 parent 456fe63 commit c57dab8
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ----------------------------------------------------------------------
# Build application using node
# ----------------------------------------------------------------------
FROM node:16.19.1 AS builder
FROM node:18.16.0 AS builder
WORKDIR /usr/src/app
ARG REACT_APP_ENV=""
ENV REACT_APP_ENV=${REACT_APP_ENV}
Expand Down Expand Up @@ -51,4 +51,4 @@ COPY --from=builder /usr/src/app/build/ .
COPY nginx.conf /etc/nginx/conf.d/default.conf

# # Run the Node.js script
# CMD ["node", "./scripts/geofilter.mjs"]
CMD ["node", "./scripts/geofilter.mjs"]
6 changes: 6 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ server {
}
location /public/ {
root /usr/share/nginx/html;
}
location /assets/ {
root /usr/share/nginx/html;
}
location /scripts/ {
root /usr/share/nginx/html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
Expand Down
3 changes: 3 additions & 0 deletions src/app.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const localConfig = {

// eslint-disable-next-line no-unused-vars
function getConfig() {
if (!process.env.APP_ENV) {
throw new Error("APP_ENV environment variable not set or being detected. You will not be able to parse your json");

Check failure on line 26 in src/app.config.js

View workflow job for this annotation

GitHub Actions / Test Suite

Replace `"APP_ENV·environment·variable·not·set·or·being·detected.·You·will·not·be·able·to·parse·your·json"` with `⏎············"APP_ENV·environment·variable·not·set·or·being·detected.·You·will·not·be·able·to·parse·your·json"⏎········`

Check failure on line 26 in src/app.config.js

View workflow job for this annotation

GitHub Actions / Test Suite

Replace `"APP_ENV·environment·variable·not·set·or·being·detected.·You·will·not·be·able·to·parse·your·json"` with `⏎············"APP_ENV·environment·variable·not·set·or·being·detected.·You·will·not·be·able·to·parse·your·json"⏎········`
}
if (process.env.APP_ENV === "local") {
return localConfig;
}
Expand Down
32 changes: 29 additions & 3 deletions src/utils/apiutil.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
export async function getJsonDataFromUrl(url) {
const response = await fetch(url, { method: "GET", mode: "cors" });
if (response.status === 200) {
return response.json();
if (response.ok) {
const responseBody = await response.text();
if (isJSON(responseBody)) {
try {
return JSON.parse(responseBody);
} catch (error) {
console.error(responseBody);
throw new Error(
"Error parsing JSON!! You either not set up environment variable correctly, or your are not fetching json"
);
}
} else {
console.error(
"Response body is not json!! You either not set up environment variable correctly, or your are not fetching json"
);
console.error(responseBody);
return [];
}
}
return [];
console.error(`Error fetching data. Status: ${response.status}`);
throw new Error(`Error fetching data. Status: ${response.status}`);
}

export function convertAllState(inlist) {
Expand Down Expand Up @@ -43,3 +60,12 @@ export const getValueFromAttrPercentage = (stateRecord, attribute): string => {
});
return ans;
};

function isJSON(str) {
try {
JSON.parse(str);
return true;
} catch (e) {
return false;
}
}

0 comments on commit c57dab8

Please sign in to comment.