Skip to content

Commit 04a64bf

Browse files
authored
Merge pull request #153 from dedis/web-backend-node-setup
Fix web backend to redirect DKG setup requests
2 parents 22c19ea + 719971c commit 04a64bf

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

docs/api.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,8 @@ Return:
329329

330330
```json
331331
{
332-
"ElectionID": "<hex encoded>"
332+
"ElectionID": "<hex encoded>",
333+
"Proxy:": ""
333334
}
334335
```
335336

@@ -351,7 +352,8 @@ Return:
351352

352353
```json
353354
{
354-
"Action": "setup"
355+
"Action": "setup",
356+
"Proxy:": ""
355357
}
356358
```
357359

web/backend/src/Server.ts

+14-4
Original file line numberDiff line numberDiff line change
@@ -400,14 +400,24 @@ function sendToDela(dataStr: string, req: express.Request, res: express.Response
400400
// we strip the `/api` part: /api/election/xxx => /election/xxx
401401
let uri = process.env.DELA_NODE_URL + req.baseUrl.slice(4);
402402

403-
// in case this is a DKG init request, we must extract the proxy addr and
404-
// update the payload.
405-
const regex = /\/evoting\/services\/dkg\/actors$/;
406-
if (uri.match(regex)) {
403+
// in case this is a DKG init request, we must also update the payload.
404+
const dkgInitRegex = /\/evoting\/services\/dkg\/actors$/;
405+
if (uri.match(dkgInitRegex)) {
407406
const dataStr2 = JSON.stringify({ ElectionID: req.body.ElectionID });
408407
payload = getPayload(dataStr2);
408+
}
409409

410+
// in case this is a DKG setup request, we must update the payload.
411+
const dkgSetupRegex = /\/evoting\/services\/dkg\/actors\/.*$/;
412+
if (uri.match(dkgSetupRegex)) {
413+
const dataStr2 = JSON.stringify({ Action: req.body.Action });
414+
payload = getPayload(dataStr2);
415+
}
416+
417+
// in case this is a DKG init or setup request, we must extract the proxy addr
418+
if (uri.match(dkgInitRegex) || uri.match(dkgSetupRegex)) {
410419
const proxy = req.body.Proxy;
420+
411421
if (proxy === undefined) {
412422
res.status(400).send('proxy undefined in body');
413423
return;

0 commit comments

Comments
 (0)