question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ability to get children of req object

See original GitHub issue

I’m trying to set a variable as the value of either req.body.token, req.query.token, or req.headers['x-access-token'] in a middleware function, but I’m running into issues.

In Express, this works:

const app = express()

function apikey(req, res, next) {
  let userToken = req.body.token || req.query.token || req.headers['x-access-token']
  if (!token) return res.status(401).end('no token provided')
  next()
}

app.use(apikey)

If a token is present in the body, it uses that, and so on.

When I try the equivalent in Polka, I’m getting a TypeError: Cannot read property 'token' of null When I use the Async example expressed in the README I actually get the same error.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
lukeedcommented, Feb 16, 2018

I’m patching it now 😃

0reactions
lukeedcommented, Feb 16, 2018

Available in 0.3.4 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pass and access request response object in child process ...
The problem with passing the request/response between parent and child is that you have to be able to serialize the objects sent back...
Read more >
Working with the request object in Express.js
When an HTTP request comes in, Express middleware methods have full access to request and response so they can modify those objects.
Read more >
How To Use the req Object in Express - DigitalOcean
Learn about using the req object in Express.js projects to examine calls from the client side, make HTTP requests, and handle incoming data ......
Read more >
Express.js req.body Property - GeeksforGeeks
The req. body property contains key-value pairs of data submitted in the request body. By default, it is undefined and is populated when...
Read more >
Pass handle representing request/response to child process
I have a Node.js server (running on Node version 9) and I want to launch a child process for a certain type of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found