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

254
Visualizações
node js proxy service issue updating port

I am trying to set the target show in my proxy options to have the same port that is coming from my bonjour service. Also if the port change I would like to run the proxy function to setting the target. any help please. The code works however the issue is that the proxy only sets once. If the value from servicePort change the proxy does not update it continues to run with the old target

const express = require("express");
const { createServer } = require("http");
const { Server } = require("socket.io");
const { WebMidi } = require("webmidi");
const { createProxyMiddleware } = require("http-proxy-middleware");
var cors = require("cors");
var bonjour = require("bonjour")();

const app = express();
const httpServer = createServer(app);

let servicePort = bonjour.find({ type: "gametime" }, function (service) {
    console.log("Found an HTTP server:", service);
    return service.port
  });

// proxy middleware options
const options = {
  target: `http://localhost:63695${servicePort}`, // target host
  changeOrigin: true, // needed for virtual hosted sites
  ws: true, // proxy websockets
};

// create the proxy (without context)
const proxyService = createProxyMiddleware(options);

// set cors
app.use(cors());

// route: forward all request to proxy service 
app.use("/", proxyService);

httpServer.listen(9080);
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