2

I have a request coming into my app that looks like this:

POST /?post%2F5125504547b49d91b2000001 200 53ms - 9.35kb

Which, when unencoded looks like:

POST /?post/5125504547b49d91b2000001 200 53ms - 9.35kb

My question, is how to I capture this with a express route?

I've tried the following:

app.all "/?post/:id",

app.all "/?post%2F:id",

Any ideas?

wesbos
  • 25,839
  • 30
  • 106
  • 143

2 Answers2

2

The route path definition is a regex so you need to double escape the question mark, which is a special character

app.all "/\\?post%2F:id"
Community
  • 1
  • 1
Pero P.
  • 25,813
  • 9
  • 61
  • 85
1

I would suggest using middleware to manipulate the url back into something 'normal' so that you can route and respond to it as you would in express.

Maybe something like this pseudo code:

  app.use(function (req, res, next) {
    if (req.originalUrl.match(/^\/(\?post)/))
      req.url = req.originalUrl = req.originalUrl.replace('%2F', '/').replace('/?','/');
    next();
  });
wesbos
  • 25,839
  • 30
  • 106
  • 143
deedubs
  • 282
  • 1
  • 6