Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!