Serve responses from a HAR file.
har-server takes a HAR file as an input, and creates a HTTP server which will replay responses from the HAR file.
npm install -g har-server
sudo har-server cnn.com.har -p 80 -h -r
A request for a resource is considered to be a match of a HAR file entry if and only if:
har-server can generate its own SSL key and certificate, or use pre-existing ones. However, loading the har file in a browser causes all sorts of SSL errors. har-server uses one key-cert pair for every domain, which causes all browsers display a warning on the page's domain, and reject all 3rd party resources. This is good for security but bad for serving HAR files.
Chrome has a command line switch to disable this check. Here are some common install locations with the switch added.
#OSX
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --ignore-certificate-errors
#Ubuntu
/opt/google/chrome/google-chrome --ignore-certificate-errors
#Windows 7 and newer
C:\Users\%USERNAME%\AppData\Local\Google\Chrome\Application\chrome.exe --ignore-certificate-errors
har-server [OPTIONS] <file.har>
The IP address to associate with DNS name in the host file. Default 127.0.0.1
The port which har-server will listen on. If below 1024 har-server must be run as root. Default 8080
Add host entries to host file. Host file location on Linux and OSX is assumed to be /etc/hosts, on Windows C:/Windows/System32/drivers/etc/hosts. If this setHostFileEntries is used and host file is not writable, then har-server will not run. Default false
When har-server receives SIGINT (ctrl+c) remove host file entries in HAR file. Must be used with setHostFileEntries. Host file location on Linux and OSX is assumed to be /etc/hosts, on Windows C:/Windows/System32/drivers/etc/hosts. If this setHostFileEntries is used and host file is not writable, then har-server will not run. Default false
Enable HTTPS server. Default false
The port to listen for HTTPS requests on. Default 4433
Generate one time use SSL cert and key. This switch is ignored if sslKeyFile or sslCertFile are set. Default true
Name of file containing SSL key to use. Must also have sslCertFile set. No default
Name of file containing SSL cert to use. Must also have sslKeyFile set. No default