My app is responding properly to https://localhost, while http://localhost gives ERR_EMPTY_RESPONSE. http://localhost should be redirected to https://localhost. How can i obtain this in pure elixir? (no phoenix or such...). Some code has been omitted for readability
https_worker.ex
defmodule MyApp.HttpsWorker do
def start_link do
Plug.Adapters.Cowboy.https MyApp.Endpoint, [],
port: Application.get_env(:my_app, :port),
password: Application.get_env(:my_app, :password),
otp_app: Application.get_env(:my_app, :otp_app),
keyfile: Application.get_env(:my_app, :keyfile),
certfile: Application.get_env(:my_app, :certfile)
end
end
application.ex
defmodule MyApp.Application do
use Application
def start(_type, _args) do
import Supervisor.Spec, warn: false
# Define workers and child supervisors to be supervised
children = [
worker(MyApp.HttpsWorker, [])
...
]
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
Supervisor.start_link(children, opts)
end
end
endpoint.ex
defmodule MyApp.Endpoint do
use Plug.Router
plug Plug.Static, at: "/", from: :my_app
plug :match
plug :dispatch
get "/" do
send_file(conn, 200, "/priv/static/login.html")
end
match _ do
send_resp(conn, 404, "oops")
end
end