mix dstar.https (dstar v0.1.0-alpha.2)

Copy Markdown View Source

Adds a development host to /etc/hosts and generates a browser-trusted development certificate with mkcert, so Datastar SSE streams run over HTTP/2 in dev without certificate warnings.

The task infers the host from:

config :my_app, dstar: [dev_url: "https://my-app.test:4001"]

If no :dev_url is configured, it falls back to the current Mix application name with underscores converted to hyphens (e.g. my-app.test).

This task asks before running local machine setup. If accepted, it may prompt for your password through sudo when updating /etc/hosts or when mkcert installs its local certificate authority. When sudo cannot prompt (e.g. some IDE terminals), it falls back to a GUI prompt on macOS via osascript.

mkcert must be installed first. On macOS:

brew install mkcert nss

After the certificate is generated, point your endpoint at it in config/dev.exs:

config :my_app, MyAppWeb.Endpoint,
  url: [scheme: "https", host: "my-app.test", port: 4001],
  https: [
    port: 4001,
    cipher_suite: :strong,
    keyfile: "priv/cert/selfsigned_key.pem",
    certfile: "priv/cert/selfsigned.pem"
  ]

Examples

mix dstar.https
mix dstar.https --host my-app.test
mix dstar.https --cert priv/cert/selfsigned.pem
mix dstar.https --key priv/cert/selfsigned_key.pem
mix dstar.https --yes

Options

  • --host - hostname to add and generate a certificate for. Defaults to the configured Dstar dev URL host.
  • --cert - certificate path. Defaults to priv/cert/selfsigned.pem.
  • --key - private key path. Defaults to priv/cert/selfsigned_key.pem.
  • --ip - IP address for the hosts entry. Defaults to 127.0.0.1.
  • --dry-run - print the commands without running them.
  • --yes - skip the confirmation prompt.