0

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
Razinar
  • 727
  • 3
  • 13
  • 21
  • Do you have something else running on port 80? Cowboy shouldn't be responding to `http://localhost` at all if your `port` in the config is 443. – Dogbert Jun 09 '17 at 08:35
  • Nothing running on port 80, port in config is set to 9000 – Razinar Jun 09 '17 at 10:16

0 Answers0