Webmachine支持http和https吗?

4

如何推荐使用webmachine实现https的工作?

我发现有一个示例可以让mochiweb和http一起工作。但是我似乎无法将其转换为webmachine。特别是如何在一个应用程序中处理http和https请求。

1个回答

7

我在演示应用程序中的mywebdemo_sup.erl文件做了以下更改,成功地实现了多个监听器。虽然我没有进行过太多的测试,但希望这足以让您开始使用。

init([]) ->
    Ip = case os:getenv("WEBMACHINE_IP") of false -> "0.0.0.0"; Any -> Any end,
    {ok, Dispatch} = file:consult(filename:join(
                    [filename:dirname(code:which(?MODULE)),
                     "..", "priv", "dispatch.conf"])),
    WebConfig = [
         {name, one},
         {ip, Ip},
         {port, 8000},
         {log_dir, "priv/log"},
         {dispatch, Dispatch}],
    Web = {one,
       {webmachine_mochiweb, start, [WebConfig]},
       permanent, 5000, worker, dynamic},
    WebSSLConfig = [
            {name, two},
            {ip, Ip},
            {port, 8443},
            {ssl, true},
            {ssl_opts, [{certfile, "/tmp/api_server.crt"},
                {cacertfile,"tmp/api_server.ca.crt"},
                {keyfile, "/tmp/api_server.key"}]},
            {log_dir, "priv/log"},
            {dispatch, Dispatch}],
    WebSSL = {two,
          {webmachine_mochiweb, start, [WebSSLConfig]},
          permanent, 5000, worker, dynamic},
    Processes = [Web, WebSSL],
    {ok, { {one_for_one, 10, 10}, Processes} }.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接