Skip to content

Instantly share code, notes, and snippets.

@nrjdalal
Last active March 21, 2022 18:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nrjdalal/0eeb873c845d3df04054589370c29a82 to your computer and use it in GitHub Desktop.
Save nrjdalal/0eeb873c845d3df04054589370c29a82 to your computer and use it in GitHub Desktop.
Serve localhost:3000 as https://localhost.next or https://anything.localhost.next via caddy dnsmasq mkcert
# ~ dnsmasq.conf
brew install dnsmasq
touch $(brew --prefix)/etc/dnsmasq.conf
read -r -d '' VAR <<END
address=/.next/127.0.0.1
END
grep -Fqx $VAR $(brew --prefix)/etc/dnsmasq.conf || echo "$VAR" >>$(brew --prefix)/etc/dnsmasq.conf
sudo mkdir -p /etc/resolver && sudo zsh -c 'echo "nameserver 127.0.0.1" >/etc/resolver/next'
sudo brew services restart dnsmasq
# ~ mkcert
brew install mkcert nss
mkdir -p $(brew --prefix)/etc/caddy/certs && cd $(brew --prefix)/etc/caddy/certs
mkcert -install && mkcert 'localhost.next' && mkcert '*.localhost.next'
# ~ Caddyfile
brew install caddy
touch $(brew --prefix)/etc/Caddyfile
read -r -d '' VAR <<END
localhost.next {
tls $(brew --prefix)/etc/caddy/certs/localhost.next.pem $(brew --prefix)/etc/caddy/certs/localhost.next-key.pem
reverse_proxy localhost:3000
}
*.localhost.next {
tls $(brew --prefix)/etc/caddy/certs/_wildcard.localhost.next.pem $(brew --prefix)/etc/caddy/certs/_wildcard.localhost.next-key.pem
reverse_proxy localhost:3000
header V-Host {labels.2}
}
END
grep -Fqx $VAR $(brew --prefix)/etc/Caddyfile || echo "$VAR" >>$(brew --prefix)/etc/Caddyfile
sudo brew services restart caddy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment