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.

Using beforeRequest to modify the request object

See original GitHub issue

I would like to use a JS file to modify the request json payload before it’s sent to the server. But it seems like it doesn’t actually effect the request object from what I’m seeing on the server.

My helper JS

const moment = require("moment");

exports.currentTime = (req, context, events, next) => {
  const unixTime = moment()
    .unix()
    .valueOf();

  req.json.timestamp = unixTime;
  return next();
};

In my config:


...
config:
  processor: "../utils/helpers.js"
...
  - name: "Flow name"
    weight: 2
    flow:
      - post:
          beforeRequest: "currentTime"
          url: "/api/route"
          json:
              timestamp: 123

When I look at the request on my server, I’m getting timestamp to be 123 and not the current time.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
robackcommented, Dec 4, 2017

I ran into the same problem. My workaround was to remove json: from the config file and then setting req.json = { timestamp: unixTime } in the helper JS file instead. (using v.1.6.0-12)

0reactions
staslevcommented, Mar 10, 2019

@misozask , try using: status: "{{status}}" (note the double quotations marks). See also this post for a complete example.

I had a similar problem and it got resolved once I added the double quotations.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to modify request body before reaching controller in ...
Use AOP to change the request before the method is called. Create an HTTP filter. Create a custom Spring HandlerInterceptor.
Read more >
Modifying a Request or Response - Fiddler Classic
It is possible to use objects from the request inside OnBeforeResponse; however, ... Change a request for one page to a different page...
Read more >
RequestHandler2 (AWS SDK for Java - 1.12.372)
A request handler is executed on a request object before it is sent to the client ... For this reason, we recommend that...
Read more >
How to change request body before sending request - Help
I just want to modify the request body before request sent. I'm reading data from json and few fields will have array of...
Read more >
StackedRequestHandler (AWS SDK for Java - Core 1.11.291 API)
beforeRequest (Request) method using AmazonWebServiceRequest.addHandlerContext(HandlerContextKey, Object) , and return your cloned message from this method. You ...
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