0

I'm trying to send a GET request to an external link [1]: https://bpdts-test-app.herokuapp.com/user/3 in attempt to store the data locally and manipulate it.

After using http-proxy-server I was able to access this link and display the data on a certain route. However, I'm unsure as how and where to create the GET request using axios.

My server.js file is as follows

const express = require("express");
const { createProxyMiddleware } = require("http-proxy-middleware");
const allRoutes = require("./routes/allRoutes");

const app = express();

app.use(
  "/user/3",
  createProxyMiddleware({
    target: "https://bpdts-test-app.herokuapp.com",
    changeOrigin: true,
    ws: true,
    logLevel: "debug"
  })
);

app.listen(5000, () => console.log("Server running on 5000"));
Maaz
  • 69
  • 1
  • 6

1 Answers1

0

You can add POST and GET request in the same file ,

  const express = require("express");
  const { createProxyMiddleware } = require("http-proxy-middleware");
  const allRoutes = require("./routes/allRoutes");

  const axios = require('axios');

 app.use(
        "/user/3",
     createProxyMiddleware({
     target: "https://bpdts-test-app.herokuapp.com",
     changeOrigin: true,
     ws: true,
     logLevel: "debug"
    })
    );


   axios({
         method: 'get',
         url: 'https://bpdts-test-app.herokuapp.com/swagger.json'
       })
      .then(function (response) {
    console.log(response.data)
    });
  app.listen(5000, () => console.log("Server running on 5000"));
Ankush Verma
  • 689
  • 1
  • 8
  • 17