diff --git a/frontend/env.js b/frontend/env.js new file mode 100644 index 00000000..e5aaee53 --- /dev/null +++ b/frontend/env.js @@ -0,0 +1,30 @@ +const fs = require("fs"); + +const data = { + test: { + REACT_APP_IDP_URL: "https://dev-is.stamacasa.ro", + REACT_APP_URL: "http://localhost:3000", + REACT_APP_API_URL: "https://dev-api.stamacasa.ro" + }, + development: { + REACT_APP_IDP_URL: "http://localhost:5001", + REACT_APP_URL: "http://localhost:3000", + REACT_APP_API_URL: "http://localhost:5008" + } +}; + +const env = process.env.NODE_ENV || "development"; + +const content = `window._env_ = { + REACT_APP_IDP_URL: "${data[env].REACT_APP_IDP_URL}", + REACT_APP_URL: "${data[env].REACT_APP_URL}", + REACT_APP_API_URL: "${data[env].REACT_APP_API_URL}", + CLIENT_ID: "js" +};`; + +try { + fs.writeFileSync("./public/env-config.js", content); + console.info("🚀 File `env-config.js` written successfully"); +} catch (err) { + console.error(err); +} diff --git a/frontend/package.json b/frontend/package.json index 6cd8c1de..fc615c38 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -23,6 +23,7 @@ "scripts": { "start": "react-scripts start", "build": "react-scripts build", + "build-test": "NODE_ENV=test node env.js && npm run build", "test": "react-scripts test", "eject": "react-scripts eject", "lint": "eslint ./src --ext .js,.jsx,.ts,.tsx",