Dehardcode backend address
Right now, the address/path for the backend is hardcoded in multiple places:
grim@hylek ~/Uninova/ZDMP/zremoteqc-frontend develop rg grisenergia.pt
src/context/user/UserState.js
97: const res = await fetch(`https://backend.zremoteqc.dev.zdmp.grisenergia.pt/start/projects/${user}`);
140: const mat = await fetch(`https://backend.zremoteqc.dev.zdmp.grisenergia.pt/list/materials/${state.selectP}`);
159: const del = await fetch(`https://backend.zremoteqc.dev.zdmp.grisenergia.pt/deliveries/orderlist?projectName=${state.selectP}&materialName=${state.selectM}`);
179: const res = await fetch(`https://backend.zremoteqc.dev.zdmp.grisenergia.pt/qcontrol/info?project_name=${state.selectP}&lotsID_show=${user}`);
197: const res = await fetch(`https://backend.zremoteqc.dev.zdmp.grisenergia.pt/qcontrol/lotDocumentation?lots_id=${user}`);
297: const res = await fetch(`https://backend.zremoteqc.dev.zdmp.grisenergia.pt/start/listProjects?project_name=${state.selectP}`);
In the near future, we will want to be able to point different frontend instances to different backend instances, so we are able to host at least two independent ones, production and staging.
Proposal: replace https://backend.zremoteqc.dev.zdmp.grisenergia.pt
with an environment variable (ex. ZREMOTEQC_BACKEND_PATH
) and have it default to https://backend.zremoteqc.zdmp.grisenergia.pt
when empty.
https://create-react-app.dev/docs/adding-custom-environment-variables/