Skip to content

Instantly share code, notes, and snippets.

@albacoretuna
Last active November 19, 2019 14:44
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 albacoretuna/b46594396bf38b5022dc7007474387c4 to your computer and use it in GitHub Desktop.
Save albacoretuna/b46594396bf38b5022dc7007474387c4 to your computer and use it in GitHub Desktop.
Serving a create react app locally with backend api

Enable port forwarding on mac locally

Imagine you'd like to use account.exapmle.com from your local dev machine, but with the backend api.

  1. Change your hosts file:
sudo vim /etc/hosts

Add this line at the end:

127.0.0.1 account.example.com
  1. Then you need to forward the https port to local port, imagine 3000 is your local server

Create /etc/pf.anchors/dev, containing:

  rdr pass inet proto tcp from any to any port 443 -> 127.0.0.1 port 3000
  1. Edit /etc/pf.conf. After rdr-anchor "com.apple/*" insert rdr-anchor "dev" (on its own line). After load anchor "com.apple" from "/etc/pf.anchors/com.apple" insert load anchor "dev" from "/etc/pf.anchors/dev" (again on its own line).

It'll look something like this:

scrub-anchor "com.apple/*"
nat-anchor "com.apple/*"
rdr-anchor "com.apple/*"
rdr-anchor "dev"
dummynet-anchor "com.apple/*"
anchor "com.apple/*"
load anchor "com.apple" from "/etc/pf.anchors/com.apple"
load anchor "dev" from "/etc/pf.anchors/dev"
  1. Test the config:
sudo pfctl -v -n -f /etc/pf.conf
  1. Then reload:
sudo pfctl -ef /etc/pf.conf

To Undo the changes

Just remove or comment out the line you added in /etc/hosts:

sudo vim /etc/hosts
#127.0.0.1 account.example.com

Last part taken from: https://gist.github.com/novemberborn/aea3ea5bac3652a1df6b

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