I’m helping someone out at a hackathon and they have local http requests working but not in production, they get this error: tcp connect error: Network is unreachable
.
Any insights?
I’m helping someone out at a hackathon and they have local http requests working but not in production, they get this error: tcp connect error: Network is unreachable
.
Any insights?
Here is the code:
import {
Server,
serialize
} from 'azle';
import express from 'express';
export default Server(() => {
const app = express();
app.use(express.json());
async function getAccounts(access_token: string) {
const authorization = 'Bearer ' + access_token;
const response = await fetch(`icp://aaaaa-aa/http_request`, {
body: serialize({
args: [
{
url: https://buildhathon-sandbox.biapi.pro/2.0/users/me/accounts,
max_response_bytes: [],
method: {
get: null
},
headers: [
{name: 'Authorization', value: authorization},
{name: 'Content-Type', value: 'application/json'}
],
body: [],
transform: []
}
],
cycles: 30000000000
})
});
return await response.json();
}
app.post('/web2/accounts', async (req, res) => {
const { access_token } = req.body;
try {
const balanceData = await getAccounts(access_token);
const serializedData = JSON.parse(Buffer.from(balanceData.body).toString('utf-8'));
res.json(serializedData);
} catch (error: any) {
const errorTxt = 'Error fetching accounts: ' + error.message;
res.status(500).json({ error: errorTxt });
}
});
app.use(express.static('/dist'));
return app.listen();
});
Maybe attempt to connect to IPv4 in a setting where only IPv6 is supported?
Yes seems so…thank you
So how did you resolve this? If the server does not allow IPv6 connections we cannot make canister http calls to it?
Yes you cannot make canister calls directly to the server in that case. A workaround can be to include a proxy IPv6 server in the middle, so your canister will make calls to this proxy and than proxy will handle calls to your primary server.
got it, Im thinking in using Cloudfront to receive the calls and then forward it to my backend (that only accepts IPv4), let me know if you have a better solution!