From 5d1004e322984e764d86a38563e9e5248bfe0688 Mon Sep 17 00:00:00 2001 From: Dinu B <32189942+dvinubius@users.noreply.github.com> Date: Tue, 15 Nov 2022 21:34:37 +0200 Subject: [PATCH] Fix Response Headers to pass the tests There is a test for each of the three post requests (contract call, get balance, transfer) which expects `'Content-Type'` to be `'application/json'` on the response header. (The test description is misleading though, because is refers to the request header) Express automatically adds `'charset=UTF-8'`, which makes the test fail. The changes in this PR fix the issue. --- .../node/provider.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build-a-web3-client-side-package-for-your-dapp/node/provider.js b/build-a-web3-client-side-package-for-your-dapp/node/provider.js index 874ac2b..ce30184 100644 --- a/build-a-web3-client-side-package-for-your-dapp/node/provider.js +++ b/build-a-web3-client-side-package-for-your-dapp/node/provider.js @@ -31,6 +31,7 @@ app.post('/call-smart-contract', async (req, res) => { try { const result = await callSmartContract(id, method, args, address); + res.contentType('application/json'); res.json({ result }); } catch (e) { logover.error(e); @@ -53,6 +54,7 @@ app.post('/get-balance', async (req, res) => { if (!balance) { return res.status(404).json({ error: 'Account not found' }); } + res.contentType('application/json'); return res.json({ result: balance }); }); @@ -68,6 +70,7 @@ app.post('/transfer', async (req, res) => { } try { await transfer({ from, to, amount }); + res.contentType('application/json'); res.json({ result: 'success' }); } catch (e) { logover.error(e);