Skip to content

Instantly share code, notes, and snippets.

@Nooshu
Forked from radum/charles-map-remote.md
Created June 28, 2017 11:40
Show Gist options
  • Save Nooshu/f9c17876da5efdd6d7288e03e287f42a to your computer and use it in GitHub Desktop.
Save Nooshu/f9c17876da5efdd6d7288e03e287f42a to your computer and use it in GitHub Desktop.
Charles proxy Map Remote over HTTP or HTTPS

Charles Proxy Map Remote over HTTP or HTTPS

The Map Remote tool changes the request location, per the configured mappings, so that the response is transparently served from the new location as if that was the original request.

HTTP

Using this feature for http resources does't require anything else apart from just configuring your Map Remote entry.

Always make sure you are clearing your cache before you test. Even if Charles is configured properly you might not see the changes unless the browser gets the resource again from the server and not for its local cache.

HTTPS

In order to use Map Remote over https you need to create a self signed certificate and launch your local server with that.

Step 1 - Create a self signed certificate

Use https://zerossl.com/free-ssl/#self or do it manually using the following commands.

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout localhost.key -out localhost.crt

Running the command above will prompt for additional information. Add whatever details you want but use localhost for Common Name.

Common Name (e.g. server FQDN or YOUR name) []:localhost

Once you are done 2 files will be created a localhost.cert and a localhost.key. Store them in a folder you can easily access when needed.

Step 2 - Add the created certificate to your Keychain

On a Mac open Keychain and use the File \ Import menu to import the newly created certificate. Make sure you select the System tab before you do it as it need to go in there.

Next, double click your new certificate and under Trust dropdown menu select Always Trust.

This will make the browser trust your certificate. The https icon on Chrome and others will be green now.

Step 3 - Tell Charles to Proxy SSL

Open Charles and from the menu select Proxy \ SSL Proxy Settings.

Add 2 items in the list. One will be your remote domain name Ex: radumicu.com or dev.radumicu.com, and another for localhost localhost:{PORT} (replace port with your port).

Step 4 - Tell Charles to install its own signed certificates

Charles in order to proxy SSL connections needs to install its own certificates. With Charles open click on the Help menu and then select SSL Proxying \ Install Charles Root Certificate

How to map remote a file

To use Map Remote, you need to have a local server running that handles your requests. You could use Pythons simple http server, but that is not very good these days and it is slower than others.

A good tool is http-server NodeJs package, but a better tool is local-web-server. local-web-server is better because it can gzip your requests, and this helps with performance profiling.

Install it globally using:

npm install -g local-web-server

And from the path you want to serve your files run:

ws -p {port} -c --key {PATH}/localhost.key --cert {PATH}/localhost.crt

Replace {port} and {PATH} with your settings.

Next configure in Charles a Map Remote entry with your current settings and your remote resource will be replaced with your local one. Remember to clear cache before you test or use Disable cache in Dev Tools.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment