Stuk / server-replay

Replay server responses from a HAR file
Apache License 2.0
140 stars 21 forks source link

server-replay

Replay server responses from a .har file.

Useful if…

It works by starting a proxy server and serving content from a previously saved .har file overlayed with files from your local system, configurable with mappings.

Installation

npm install -g server-replay

Running

You need to have a .har file, run server-replay, and then set up your browser to use it as a proxy.

A .server-replay.json in the current directory is used by default if no config option is given.

server-replay [options] <.har file>

Options:
  -c, --config  The config file to use
  -p, --port    The port to run the proxy server on  [default: 8080]
  -d, --debug   Turn on debug logging

See the Setup section for details on creating .har file and using the proxy in your browser.

Configuration

The config file is a JSON file (plus // comments) with the following properties:

Full example:

{
    "version": 1,
    "mappings": [
        {
            "match": {"regex": ".*\\/static\\/(.*)"},
            "path": "./public/$1"
        }
    ],
    "replacements": [
        // For JSONP requests where callback name is randomly generated
        {
            "match": {"var": "entry.request.parsedUrl.query.callback"},
            "replace": {"var": "request.parsedUrl.query.callback"}
        },
        // Proxy only works over http
        {"match": "https", "replace": "http"}
    ]
}

Types

The types mentioned above take the following forms:

Variables

Setup

Getting a .har file

The easiest way is with the Chrome DevTools. In the Network panel disable the cache, refresh the page and interact with the page to generate the network requests that you want to capture. Then right click and select "Save as HAR with Content".

Creating a .har file

Note: Extensions such as AdBlock and Ghostery interfere with the recorded responses. Be aware of this and, if necessary, disable them before loading the page.

Browser proxy configuration

Chrome

Launch with the --proxy-server argument:

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --proxy-server=127.0.0.1:8080

Firefox

Preferences > Advanced > Network > Settings… > Manual proxy configuration

Firefox proxy settings

License

Copyright 2015 Adobe Systems Incorporated

This software is licensed under the Apache License, Version 2.0 (see LICENSE file).