Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

172
Visualizações
How to use data returned from an HTTP request using http-proxy-middleware and Express

I am making API calls to Squarespace for an inventory management system. I've set up a Node.js and Express server, and have been using http-proxy-middleware to set up a proxy and make GET requests.

I am able to generate the GET requests successfully on my localhost - an HTML pre-tag is filled with all of the JSON data of the request. However, I am completely clueless on how to handle and use the data further that was returned to me. When I make a call and receive Pending orders, I want to pull JSON data from the returned request body of the orders, such as SKU numbers for products purchased.

    const { response } = require('express');
    const express = require('express'); 
    require("dotenv").config();
    const { createProxyMiddleware, responseInterceptor } = require('http-proxy-middleware');
    const router = express.Router();

    const PORT = 3000; 
    const HOST = "localhost";
    const GET_ORDERS_URL = process.env.SS_GET_ORDERS_URL;
    const API_KEY = process.env.SS_AUTH;

    const app = express(); 

    const proxy = app.use("/testing", createProxyMiddleware({
        target: GET_ORDERS_URL,
        headers: {
            'Authorization': API_KEY,
            'User-Agent': 'halp me'
        },
        changeOrigin: true,
        pathRewrite: {
            [`^/testing`]: '',
        },
        selfHandleResponse: true, // 
        onProxyRes: responseInterceptor(async (responseBuffer, proxyRes, req, res) => {
          
            var orderResponse = responseBuffer.toString('utf-8');
            return orderResponse;
        }),
      }));


    // Start Proxy
    app.listen(PORT, HOST, () => {
        console.log(`Starting Proxy at ${HOST}:${PORT}`);
    });

The API request returns JSON data, which I would love to use and process for the next part of my inventory management. I'm trying to figure out why I can't get return orderResponse; to output anything at all.

I have tried every variation of returning a variable I can imagine, console.logged a million things - any guidance to what I'm missing here would be greatly appreciated!

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda