View Source SSL
Prefer to do local development using SSL to resemble production as much as possible.
Phoenix has a generator for creating a self-signed certificate for HTTPS testing: mix phx.gen.cert
.
However, when using Phoenix's generator you'll still have a "non secure" warning. To get rid of that warning, you can generate a certificate using mkcert.
After you install mkcert
, follow the steps below:
- Create a
cert
directory underpriv
:mkdir priv/cert
. - Generate a new certificate:
mkcert -key-file priv/cert/selfsigned_key.pem -cert-file priv/cert/selfsigned.pem localhost
. - Restart your local server:
mix phx.server
. You may also need to restart your browser.
Zoonk is a multi-tenant app. Multiple schools can visit this app using their custom domain or our subdomain (i.e. username.zoonk.io
). Therefore, it's useful to test those domains locally. You can do so by following the steps below:
setting-up-dnsmasq
Setting up dnsmasq
dnsmasq
allows you to resolve domains to your local machine without having to change your /etc/hosts
file. To install dnsmasq
:
brew install dnsmasq
# Create a configuration directory
mkdir -pv $(brew --prefix)/etc/
# Set up your domains
echo 'address=/zoonk.io/127.0.0.1' >> $(brew --prefix)/etc/dnsmasq.conf
echo 'address=/.zoonk.io/127.0.0.1' >> $(brew --prefix)/etc/dnsmasq.conf
# Start dnsmasq
sudo brew services start dnsmasq
# Add dnsmasq to your resolver
sudo mkdir -v /etc/resolver
sudo bash -c 'echo "nameserver 127.0.0.1" > /etc/resolver/zoonk.io'
Note: After changing your dnsmasq.conf
file, you'll need to restart dnsmasq
generate-a-certificate-for-each-domain
Generate a certificate for each domain
You can use mkcert
to generate a certificate for each domain. In the example below, we're going to use the same domains as above:
mkcert -key-file priv/cert/selfsigned_key.pem -cert-file priv/cert/selfsigned.pem localhost zoonk.io "*.zoonk.io"
start-your-local-server
Start your local server
That's it! You can now start your local server (mix phx.server
) and test your domains using:
- https://zoonk.io:4001
- https://rug.zoonk.io:4001 (each school username can be used as a subdomain of zoonk.io)
- Or any other domain you added before.