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

169
Vistas
express static routes are not working when adding a validation middleware

I am trying to add a validation middleware in order to protect my server data. When I get request (http://localhost:3000/filepath) the static route without the middleware:

app.use(express.static('data'));

I get a status 200 OK. But when I tried to get request the same route, but this time using a simple middleware as recommended in this other question (Is it possible to use validation with express static routes?)

var staticMiddleware = function(req, res, next){
    console.log("middleware")
    next();
}

app.use(staticMiddleware, express.static('data'));

I`ve got a status 404 not found.

How can I add another middleware to app.use before the express.static middleware?

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

0

You need to add them seperately.

app.use(express.static('data'));

var staticMiddleware = function(req, res, next){
    console.log("middleware")
    next();
}

app.use(staticMiddleware );
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