Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Serving a create react app locally with backend api

Port forwarding on mac locally

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

  1. You need to change your hosts file:
sudo vim /etc/hosts

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 -> port 3000

Edit /etc/pf.conf. After rdr-anchor "*" insert rdr-anchor "dev" (on its own line). After load anchor "" from "/etc/pf.anchors/" insert load anchor "dev" from "/etc/pf.anchors/dev" (again on its own line). It'll look something like this:

scrub-anchor "*"
nat-anchor "*"
rdr-anchor "*"
rdr-anchor "dev"
dummynet-anchor "*"
anchor "*"
load anchor "" from "/etc/pf.anchors/"
load anchor "dev" from "/etc/pf.anchors/dev"

Test the config:

sudo pfctl -v -n -f /etc/pf.conf

Then reload:

sudo pfctl -ef /etc/pf.conf

Last part taken from:

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