标签: phoenix-framework

Phoenix 套接字多重分配

我想添加一些数据socket,但想知道最好的方法是什么。

而不是做一堆

socket = assign(socket, :channel_id, channel_id)

elixir phoenix-framework phoenix-channels

1
推荐指数
1
解决办法
658
查看次数

如何让 Phoenix 处理多个域?

凤凰城的 Web 应用程序。Nginx 用作反向代理。

目前,与往常一样,Web 应用程序处理单个域的请求。如果我将其他域的 DNS 指向同一服务器,我需要更改什么才能让我的 Phoenix 应用程序处理这些域的请求?

服务器上的 Web 应用程序将保留在单个实例中。并且它将可以通过多个域进行访问。不会重定向到主域 - 每个域都会像主域一样处理请求。

elixir phoenix-framework

1
推荐指数
1
解决办法
793
查看次数

将 elixir livebook 连接到正在运行的 phoenix 应用程序

为什么我想做呢?

  • 允许数据科学家使用所有业务逻辑功能

环境

  • Nginx 作为反向代理
  • Phoenix 应用程序(没有 dockermix release和 systemd)
  • 直播簿

全部运行在 VPS (Ubuntu) 上

到目前为止我做了什么

使用以下命令运行 livebook
LIVEBOOK_IP=<IP> LIVEBOOK_PORT=8089 LIVEBOOK_PASSWORD=<PASS> LIVEBOOK_COOKIE=<COOKIE> livebook server --name livebook@127.0.0.1 可以通过 IP 和端口在浏览器中访问。

mix release使用环境变量运行phoenix应用程序

      RELEASE_COOKIE: ${{ secrets.RELEASE_COOKIE }}
      RELEASE_DISTRIBUTION: name (literally)
      RELEASE_NAME: <appname>
      RELEASE_NODE: <appname>@<PUBLIC_IP>
Run Code Online (Sandbox Code Playgroud)

我尝试在同一台机器上运行没有 docker 的 livebook,以确保它们能够连接,但到目前为止还没有运气。

什么不起作用

从 Livebook 连接到 phoenix 应用程序既不能从本地安装的 Livebook 上也不能从部署在服务器上的 Livebook 上工作。我正在关注的屏幕截图教程在这里:fly.io 链接 它说该节点无法访问。 错误信息

deployment elixir phoenix-framework

1
推荐指数
1
解决办法
893
查看次数

你好,我用 phoenix 框架创建了 Elixir 项目。当我构建该文件时,有 yaml 文件,我收到此错误

== Compilation error in file lib/ecto/query.ex ==
** (Kernel.TypespecError) lib/ecto/query.ex:428: type dynamic/0 is a built-in type and it cannot be redefined
    (elixir 1.15.0) lib/kernel/typespec.ex:961: Kernel.Typespec.compile_error/2
    (stdlib 5.0.1) lists.erl:1599: :lists.foldl_1/3
    (elixir 1.15.0) lib/kernel/typespec.ex:226: Kernel.Typespec.translate_typespecs_for_module/2
could not compile dependency :ecto, "mix compile" failed. Errors may have been logged above. You can recompile this dependency with "mix deps.compile ecto --force", update it with "mix deps.update ecto" or clean it with "mix deps.clean ecto"
ERROR: Service 'cense_live_chat' failed to build: The command '/bin/sh -c …
Run Code Online (Sandbox Code Playgroud)

elixir-mix elixir ecto phoenix-framework

1
推荐指数
1
解决办法
894
查看次数

Elixir(Ecto)中的包含方法是什么?

我们在Rails中使用包含或其他类似的连接方法(或SQL);
那么函数在Elixir(Ecto)中解决了这个问题?

elixir ecto phoenix-framework

0
推荐指数
1
解决办法
187
查看次数

应用程序无法启动,出现错误"无法启动子项:Odt.Endpoint"

命令"mix phoenix.server"后总是收到错误:

=INFO REPORT==== 14-Dec-2015::20:55:48 ===

    application: logger
    exited: stopped
    type: temporary

** (Mix) Could not start application odt: Odt.start(:normal, []) returned an error: shutdown: failed to start child: Odt.Endpoint

** (Exit) shutdown: failed to start child: Phoenix.Endpoint.Server

** (Exit) shutdown: failed to start child: {:ranch_listener_sup, Odt.Endpoint.HTTP}

** (Exit) shutdown: failed to start child: :ranch_acceptors_sup

** (Exit) {:listener_error, Odt.Endpoint.HTTP, :eaddrinuse}
Run Code Online (Sandbox Code Playgroud)

我该如何解决?我究竟做错了什么?

ubuntu elixir phoenix-framework

0
推荐指数
1
解决办法
1337
查看次数

回购如何找出表格名称?

我还有一个新手问题。当我做类似的事情

case MyRepo.insert %Post{title: "Ecto is great"} do
  {:ok, struct}       -> # Inserted with success
  {:error, changeset} -> # Something went wrong
end
Run Code Online (Sandbox Code Playgroud)

Repo如何知道要使用数据库中的哪个表?

elixir ecto phoenix-framework

0
推荐指数
1
解决办法
718
查看次数

Phoenix / Elixir-cURL有效,但是HTTPoison失败

在我的Phoenix应用程序中,我试图使用HTTPoison HTTP客户端(https://hexdocs.pm/httpoison/api-reference.html)向AgileCRM API发出发布请求。我能够使用cURL发出成功的请求,但是我尝试在Phoenix中复制它的尝试失败,出现401 UNAUTHORIZED错误。

我成功的cURL:

$ curl https://domain.agilecrm.com/dev/api/contacts/search/email \
-H "Accept: application/json" \
-d 'email_ids=["contact@test.com"]' \
-u admin@test.com:api_key
Run Code Online (Sandbox Code Playgroud)

返回状态200和请求的数据。

我失败的HTTPoison:

url = "https://domain.agilecrm.com/dev/api/contacts/search/email"
body = Poison.encode!(%{"body": "email_ids=['contact@test.com']"})
headers = [{"Accept", "application/json"}, {"Authorization", "admin@test.com:api_key"}]

response = HTTPoison.post!(url, body, headers)

IO.inspect response
Run Code Online (Sandbox Code Playgroud)

哪个返回

%HTTPoison.Response{body: "<html><head>\n<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">\n<title>401 UNAUTHORIZED</title>\n</head>\n<body text=#000000 bgcolor=#ffffff>\n<h1>Error: UNAUTHORIZED</h1>\n</body></html>\n",
headers: [{"X-TraceUrl", "/appstats/details?time=1509129565372&type=json"},
{"WWW-Authenticate", "Basic realm=\"agilecrm\""},
{"Content-Type", "text/html; charset=utf-8"},
{"X-Cloud-Trace-Context", "8de994n2tbu2o356891bc3e6"},
{"Date", "Fri, 27 Oct 2017 18:39:25 GMT"}, {"Server", "Google Frontend"},
{"Content-Length", "200"}],
request_url: "https://domain.agilecrm.com/dev/api/contacts/search/email", status_code: …
Run Code Online (Sandbox Code Playgroud)

curl elixir phoenix-framework httpoison agile-crm

0
推荐指数
1
解决办法
599
查看次数

Phoenix Websocket socket.disconnect()与channel.leave()

我正在阅读有关如何从套接字断开连接或离开通道的phoenix文档

我天真的理解是 channel#leave

取消订阅服务器事件,并指示通道在服务器上终止

socket#disconnect维护通道服务器端,以便重新连接。

因此,我的问题是何时使用一个与另一个。

听起来有两种情况需要考虑:

  1. 还有其他客户端订阅了相同的频道,因此#leave将切断他们的连接,而倾向于#disconnect
  2. 但是,如果存在用户/帐户损耗,则从不调用来leave维护服务器上的“死”通道,而对于长时间运行的进程,这可能是一个问题吗?

我在想这个吗?如果我们选择只使用#disconnect-roll,我们是否应该实施定期的清理任务以杀死长时间运行的“死”通道?

谢谢!

elixir websocket phoenix-framework

0
推荐指数
1
解决办法
597
查看次数

当前状态章当前状态Phoenix 1.4.6指南针对标识符“ socket”的加注已经声明

我正在阅读《凤凰城指南》 1.4.6,并且正在“ 存在”这一章中。因此,我遵循本章的所有步骤,而我的控制台javascript对此有所抱怨:

app.js:1 Uncaught Error: Module build failed: SyntaxError: /Users/romenigld/workspace/phoenix/hello/assets/js/app.js: Identifier 'socket' has already been declared (21:4)

  19 | import {Socket, Presence} from "phoenix"
  20 | 
> 21 | let socket = new Socket("/socket", {
     |     ^
  22 |   params: {user_id: window.location.search.split("=")[1]}
  23 | })
  24 | 
    at Parser.raise (:4000/Users/romenigld/workspace/phoenix/hello/assets/node_modules/@babel/parser/lib/index.js:6322)
    at ScopeHandler.checkRedeclarationInScope (:4000/Users/romenigld/workspace/phoenix/hello/assets/node_modules/@babel/parser/lib/index.js:3754)
    at ScopeHandler.declareName (:4000/Users/romenigld/workspace/phoenix/hello/assets/node_modules/@babel/parser/lib/index.js:3720)
    at Parser.checkLVal (:4000/Users/romenigld/workspace/phoenix/hello/assets/node_modules/@babel/parser/lib/index.js:8006)
    at Parser.parseVarId (:4000/Users/romenigld/workspace/phoenix/hello/assets/node_modules/@babel/parser/lib/index.js:10441)
    at Parser.parseVar (:4000/Users/romenigld/workspace/phoenix/hello/assets/node_modules/@babel/parser/lib/index.js:10412)
    at Parser.parseVarStatement (:4000/Users/romenigld/workspace/phoenix/hello/assets/node_modules/@babel/parser/lib/index.js:10234)
    at Parser.parseStatementContent (:4000/Users/romenigld/workspace/phoenix/hello/assets/node_modules/@babel/parser/lib/index.js:9830)
    at Parser.parseStatement (:4000/Users/romenigld/workspace/phoenix/hello/assets/node_modules/@babel/parser/lib/index.js:9763)
    at Parser.parseBlockOrModuleBlockBody …
Run Code Online (Sandbox Code Playgroud)

elixir elixir-framework phoenix-framework phoenix-channels

0
推荐指数
1
解决办法
53
查看次数