Skip to content

Instantly share code, notes, and snippets.

@huksley
Created April 11, 2023 12:36
Show Gist options
  • Save huksley/f181bc7a092295e1cf665f739087725c to your computer and use it in GitHub Desktop.
Save huksley/f181bc7a092295e1cf665f739087725c to your computer and use it in GitHub Desktop.
Intercept and log HTTP(s) requests. Direct socket connections are not logged
const nock = require("nock");
nock.recorder.rec({
output_objects: true,
logging: o => {
const oo =
typeof o === "string"
? JSON.parse(o.substring(0, o.lastIndexOf("}") + 1).substring(o.indexOf("{")))
: o;
logger.info(
"Intercepted HTTP request",
oo.method,
oo.scope + oo.path,
"status",
oo.status,
"request body",
oo.body
);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment