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

160
Views
Cómo usar una variable en dos middlewares nodeJS

Estoy tratando de usar una variable en dos middlewares pero dice (no está definido)

ejemplo:

 //1st middleware app.use((req, res, next) =>{ contentType = req.headers['content-type']; if(contentType === 'application/x-www-form-urlencoded'){ next(); } }) //2nd middleware app.use({ )

este es solo un ejemplo, así que tenga la amabilidad de decirme cómo haría ( contentType ) como una variable accesible desde el segundo middleware.

Muchas gracias

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Aquí tienes, compañero. básicamente, la función expressJWT() devuelve un middleware que toma 3 parámetros, req, res, y luego se usa para ir al siguiente middleware, así que lo que hice fue usar los parámetros con expressJWT.

 //1st middleware app.use((req, res, next) =>{ req.contentType = req.headers['content-type']; if(req.contentType === 'application/x-www-form-urlencoded'){ next(); } }) //2nd middleware app.use((req, res, next) => expressJWT({ secret: jwk.expressJwtSecret({ jwksUri: req.contentType }), })(req, res, next))
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!