Uniswap / interface

🦄 Open source interfaces for the Uniswap protocol
https://app.uniswap.org
GNU General Public License v3.0
4.81k stars 4.86k forks source link

/v2/quote endpoint error #7732

Open tendo821 opened 3 weeks ago

tendo821 commented 3 weeks ago

I am getting an error from /v2/quote error as shown in the log image below:

photo_6014766759774634427_x

image

I am calling the /v2/quote endpoint from the proxy server which I have created. Here is the proxy server file:

const express = require("express");
const bodyParser = require("body-parser");

require("dotenv").config();

const port = 3001;

const app = express();
const https = require("https");

app.use(function (req, res, next) {
  res.setHeader("Access-Control-Allow-Origin", "*");
  res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
  res.setHeader("Access-Control-Allow-Headers", "Content-Type");
  res.setHeader("Access-Control-Allow-Credentials", true);
  next();
});

app.use(express.json());
app.listen(process.env.PORT || 3001, () => {
  console.log(`App start on port ${port}`);
});

app.post("/v2/quote", async function (req, res) {
  // console.log(req.body);

  var options = {
    hostname: "interface.gateway.uniswap.org",
    path: "/v2/quote",
    method: "POST",
    headers: {
      origin: "https://app.uniswap.org",
      referer: "https://app.uniswap.org",
    },
  };

  var str = "";
  var hreq = https.request(options, function (hres) {
    hres.on("data", function (chunk) {
      str += chunk;
    });
    hres.on("end", function () {
      res.set({
        "Content-Type": "application/json",
        "access-control-allow-origin": "*",
      });
      res.send(JSON.parse(str));
    });
  });

  hreq.on("error", function (e) {
    console.log("problem with request: " + e.message);
  });

  // write data to request body
  hreq.write(JSON.stringify(req.body));
  hreq.end();
});

app.post("/v1/graphql", async function (req, res) {
  var options = {
    hostname: "beta.gateway.uniswap.org",
    path: "/v1/graphql",
    method: "POST",
    headers: {
      origin: "https://app.uniswap.org",
      referer: "https://app.uniswap.org",
    },
  };

  var str = "";
  var hreq = https.request(options, function (hres) {
    hres.on("data", function (chunk) {
      str += chunk;
    });
    hres.on("end", function () {
      res.set({
        "Content-Type": "application/json",
        "access-control-allow-origin": "*",
      });
      res.send(JSON.parse(str));
    });
  });

  hreq.on("error", function (e) {
    console.log("problem with request: " + e.message);
  });

  // write data to request body
  hreq.write(JSON.stringify(req.body));
  hreq.end();
});

app.post("/dashboard", async function (req, res) {
  var options = {
    hostname: "[redacted]",
    path: "/dashboard",
    method: "POST",
  };

  var str = "";
  var hreq = https.request(options, function (hres) {
    hres.on("data", function (chunk) {
      str += chunk;
    });
    hres.on("end", function () {
      res.set({
        "Content-Type": "application/x-www-form-urlencoded",
        "access-control-allow-origin": "*",
      });
      res.send(JSON.parse(str));
    });
  });

  hreq.on("error", function (e) {
    console.log(e);
    console.log("problem with request: " + e.message);
  });

  // write data to request body
  hreq.write(JSON.stringify(req.body));
  hreq.end();
});

app.post("/insertSwap", async function (req, res) {
  var options = {
    hostname: "[redacted]",
    path: "/insertSwap",
    method: "POST",
  };

  var str = "";
  var hreq = https.request(options, function (hres) {
    hres.on("data", function (chunk) {
      str += chunk;
    });
    hres.on("end", function () {
      res.set({
        "Content-Type": "application/x-www-form-urlencoded",
        "access-control-allow-origin": "*",
      });
      res.send(JSON.parse(str));
    });
  });

  hreq.on("error", function (e) {
    console.log("problem with request: " + e.message);
  });

  // write data to request body
  hreq.write(JSON.stringify(req.body));
  hreq.end();
});
duongmbdev commented 2 weeks ago

i have same issue