Skip to content

Commit

Permalink
Merge pull request #18 from c4dt/cleanup_frontend
Browse files Browse the repository at this point in the history
Cleanup frontend
  • Loading branch information
ineiti committed Oct 4, 2023
2 parents a73ff85 + 76acfb0 commit 6fc65fc
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
5 changes: 5 additions & 0 deletions scripts/local_vars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ export SESSION_SECRET="session secret"
export REACT_APP_NOMOCK=on
# shellcheck disable=SC2155
export DB_PATH="$(pwd)/nodes/llmdb"
# The following two variables can be set to see log output from dela:
#export PROXY_LOG=info
#export LLVL=info
# If this is set, you can login without Gaspar
export REACT_APP_DEV_LOGIN="true"
4 changes: 2 additions & 2 deletions web/backend/src/controllers/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { getUserPermissions, readSCIPER, setMapAuthorization } from '../authMana
export const authenticationRouter = express.Router();

authenticationRouter.get('/get_dev_login', (req, res) => {
if (process.env.NODE_ENV !== 'development') {
const err = `/get_dev_login can only be called in development: ${process.env.NODE_ENV}`;
if (process.env.REACT_APP_DEV_LOGIN !== 'true') {
const err = `/get_dev_login can only be called with DEV_LOGIN===true: ${process.env.DEV_LOGIN}`;
console.error(err);
res.status(500).send(err);
return;
Expand Down
8 changes: 4 additions & 4 deletions web/backend/src/controllers/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ proxiesRouter.put('/:nodeAddr', (req, res) => {
const proxy = proxiesDB.get(nodeAddr);

if (proxy === undefined) {
res.status(404).send('not found');
res.status(404).send(`proxy ${nodeAddr} not found`);
return;
}
try {
const bodydata = req.body;
if (bodydata.Proxy === undefined) {
res.status(400).send('bad request, proxy is undefined');
res.status(400).send(`bad request, proxy ${nodeAddr} is undefined`);
return;
}

Expand Down Expand Up @@ -70,7 +70,7 @@ proxiesRouter.delete('/:nodeAddr', (req, res) => {
const proxy = proxiesDB.get(nodeAddr);

if (proxy === undefined) {
res.status(404).send('not found');
res.status(404).send(`proxy ${nodeAddr} not found`);
return;
}

Expand Down Expand Up @@ -98,7 +98,7 @@ proxiesRouter.get('/:nodeAddr', (req, res) => {
const proxy = proxiesDB.get(decodeURIComponent(nodeAddr));

if (proxy === undefined) {
res.status(404).send('not found');
res.status(404).send(`proxy ${nodeAddr} not found`);
return;
}

Expand Down
25 changes: 13 additions & 12 deletions web/frontend/src/pages/form/components/DKGStatusRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ const DKGStatusRow: FC<DKGStatusRowProps> = ({
// already fetched)
useEffect(() => {
if (node !== null && proxy === null) {
var error;
const fetchNodeProxy = async () => {
try {
setTimeout(() => {
Expand All @@ -209,29 +210,29 @@ const DKGStatusRow: FC<DKGStatusRowProps> = ({
const response = await fetch(endpoints.getProxyAddress(node), request);

if (!response.ok) {
const js = await response.json();
throw new Error(JSON.stringify(js));
error = Error(await response.text());
} else {
let dataReceived = await response.json();
return dataReceived as NodeProxyAddress;
}
} catch (e) {
let errorMessage = t('errorRetrievingProxy');

// Error triggered by timeout
if (e instanceof DOMException) {
errorMessage += t('proxyUnreachable', { node: node });
error = t('proxyUnreachable', { node: node });
} else {
errorMessage += t('error');
error = t('error');
}
error += e;
}
let errorMessage = t('errorRetrievingProxy');
errorMessage += error;

setInfo(errorMessage + e.message);
setStatus(NodeStatus.Unreachable);
setInfo(errorMessage);
setStatus(NodeStatus.Unreachable);

// if we could not retrieve the proxy still resolve the promise
// so that promise.then() goes to onSuccess() but display the error
return { NodeAddr: node, Proxy: '' };
}
// if we could not retrieve the proxy still resolve the promise
// so that promise.then() goes to onSuccess() but display the error
return { NodeAddr: node, Proxy: '' };
};

setDKGLoading(true);
Expand Down
3 changes: 2 additions & 1 deletion web/frontend/src/pages/session/HandleLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { FlashLevel, FlashState } from 'index';

// The backend will provide the client the URL to make a Tequila authentication.
// We therefore redirect to this address.
// If REACT_APP_DEV_LOGIN === "true", we allow an automatic login with SCIPER 100100.
const handleLogin = async (fctx: FlashState) => {
try {
let res;
if (process.env.NODE_ENV === 'development') {
if (process.env.REACT_APP_DEV_LOGIN === 'true') {
await fetch(ENDPOINT_DEV_LOGIN);
window.location.reload();
return;
Expand Down

0 comments on commit 6fc65fc

Please sign in to comment.