Skip to content

Instantly share code, notes, and snippets.

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

Enable port forwarding on mac locally

Imagine you'd like to use 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:
  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 -> port 3000
  1. 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"
  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

Last part taken from:

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