Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

195
Vistas
Dynamic endpoint with express

I'm trying to generate a dynamic URL that will change everytime an endpoint is called So I have this simple function in Node.js to create a dynamic url:

var path = crypto.createHash('md5').update(`${Date.now()}`).digest("hex");

function createNewPath(){
  path = crypto.createHash('md5').update(`${Date.now()}`).digest("hex");
}

and this simple code to receive the request:

app.use('/'+path, function(req,res){
  createNewPath();
  res.send("<h1>Welcome!<h1>");
});

The problem is that app.use does not reload the value in "path" so the initial url asigned stays the same, any ideas?

Been breaking my head and got nothing

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Don't create the route dynamically. Set it up in advance. Check the hash inside it.

Create a route which takes the hash as a param.

Return an error if it doesn't match.

app.get("/:hash", (req, res) => {

    if (req.params.hash === path) {
        return res.send("<h1>Welcome!<h1>");
    }
    return res.sendStatus(404);
});
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda