Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

85
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?

7 months 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 );
7 months 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 job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.