我的应用程序正确响应https://localhost,而http://localhost提供 ERR_EMPTY_RESPONSE。 http://localhost应该被重定向到https://localhost。我怎样才能在纯灵药中获得这个?(没有凤凰之类的......)。为了便于阅读,省略了一些代码
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
应用程序.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
端点.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