Skip to content

Instantly share code, notes, and snippets.

@cortezcristian
Last active August 31, 2018 00:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cortezcristian/6b26a216c1144b632175ff404218ba1f to your computer and use it in GitHub Desktop.
Save cortezcristian/6b26a216c1144b632175ff404218ba1f to your computer and use it in GitHub Desktop.

Get the info

const _ = require('lodash');
const fs = require('fs');
const agent = require('superagent');

const readJson = (path, cb) => {
  fs.readFile(require.resolve(path), (err, data) => {
    if (err)
      cb(err)
    else
      cb(null, JSON.parse(data))
  })
}

let harFile = {};
readJson("./localhost.har", (err, data) => {
  // console.log(data);
  harFile = data;
  const entries = _.get(harFile, 'log.entries')
  // console.log(entries[0]);
  const req = _.get(entries[0], 'request');
  // console.log(req);
  const method = _.get(req, 'method');
  agent(method.toUpperCase(), 'http://localhost:8080/'+_.get(req, 'url'))
    .set(_.get(req, 'headers')) // TODO: check if accepts []
    .query(_.get(req, 'queryString')) // TODO: check if accepts []
    .then(console.log)
    .catch(console.log)
  // cookies .set('Cookie',
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment