尝试在chrome dev控制台

时间:2017-05-22 03:58:34

标签: react-native elixir ecto elixir-framework

As per this Github answer - 我需要在native native中实现这一行代码,以便在chrome dev控制台中查看我的网络请求:

GLOBAL.XMLHttpRequest = GLOBAL.originalXMLHttpRequest || GLOBAL.XMLHttpRequest

但是当我这样做时,我从我的前端发送到我的localhost Elixir后端的请求产生了这个错误:

15:48:41.502 [error] #PID<0.406.0> running Api.Router terminated
Server: 192.168.20.3:4000 (http)
Request: GET /favicon.ico
** (exit) an exception was raised:
    ** (FunctionClauseError) no function clause matching in Api.Router.do_match/4
        (api) lib/api/router.ex:14: Api.Router.do_match(%Plug.Conn{adapter: {Plug.Adapters.
Cowboy.Conn, :...}, assigns: %{}, before_send: [], body_params: %Plug.Conn.Unfetched{aspect
: :body_params}, cookies: %Plug.Conn.Unfetched{aspect: :cookies}, halted: false, host: "192
.168.20.3", method: "GET", owner: #PID<0.406.0>, params: %Plug.Conn.Unfetched{aspect: :para
ms}, path_info: ["favicon.ico"], path_params: %{}, peer: {{192, 168, 20, 3}, 58348}, port:
4000, private: %{}, query_params: %Plug.Conn.Unfetched{aspect: :query_params}, query_string
: "", remote_ip: {192, 168, 20, 3}, req_cookies: %Plug.Conn.Unfetched{aspect: :cookies}, re
q_headers: [{"host", "192.168.20.3:4000"}, {"connection", "keep-alive"}, {"user-agent", "Mo
zilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome
/58.0.3029.110 Safari/537.36"}, {"accept", "image/webp,image/*,*/*;q=0.8"}, {"referer", "ht
tp://192.168.20.3:4000/categories"}, {"accept-encoding", "gzip, deflate, sdch"}, {"accept-l
anguage", "en-GB,en-US;q=0.8,en;q=0.6"}, {"origin", "http://evil.com/"}], request_path: "/f
avicon.ico", resp_body: nil, resp_cookies: %{}, resp_headers: [{"cache-control", "max-age=0
, private, must-revalidate"}], scheme: :http, script_name: [], secret_key_base: nil, state:
 :unset, status: nil}, "GET", ["favicon.ico"], "192.168.20.3")
        (api) lib/api/router.ex:1: Api.Router.plug_builder_call/2
        (api) lib/plug/debugger.ex:123: Api.Router.call/2
        (plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade
/4
        (cowboy) /Users/Ben/Development/Projects/vepo/api/deps/cowboy/src/cowboy_protocol.e
rl:442: :cowboy_protocol.execute/4

所以上面的代码行正在对Elixir不喜欢的网络请求做些什么。在错误中,它抱怨lib/api/router.ex:14lib/api/router.ex:1这只是:  1:defmodule Api.Router do 14:get "/" do

对错误的任何帮助表示赞赏。

编辑:错误恰好发生在router.ex的第一条路径上。我删除了所有路径,除了:

  get "/categories/" do
    Api.Repo.getCategories(conn)
  end

现在它发生在get "/categories/" do

问题中最重要的代码的主要变化是它意味着我必须启用我使用浏览器插件执行的CORS,所以也许E​​lixir不喜欢这样。

我补充说:

  get "/favicon.ico" do
    # Api.Repo.getCategories(conn)
  end

现在错误是这样的:

17:17:05.354 [error] #PID<0.370.0> running Api.Router terminated
Server: 192.168.20.3:4000 (http)
Request: OPTIONS /categories
** (exit) an exception was raised:
    ** (FunctionClauseError) no function clause matching in Api.Router.do_match/4
        (api) lib/api/router.ex:13: Api.Router.do_match(%Plug.Conn{adapter: {Plug.Adapters.
Cowboy.Conn, :...}, assigns: %{}, before_send: [], body_params: %Plug.Conn.Unfetched{aspect
: :body_params}, cookies: %Plug.Conn.Unfetched{aspect: :cookies}, halted: false, host: "192
.168.20.3", method: "OPTIONS", owner: #PID<0.370.0>, params: %Plug.Conn.Unfetched{aspect: :
params}, path_info: ["categories"], path_params: %{}, peer: {{192, 168, 20, 3}, 50258}, por
t: 4000, private: %{}, query_params: %Plug.Conn.Unfetched{aspect: :query_params}, query_str
ing: "", remote_ip: {192, 168, 20, 3}, req_cookies: %Plug.Conn.Unfetched{aspect: :cookies},
 req_headers: [{"host", "192.168.20.3:4000"}, {"connection", "keep-alive"}, {"access-contro
l-request-method", "GET"}, {"origin", "http://evil.com/"}, {"user-agent", "Mozilla/5.0 (Mac
intosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110
 Safari/537.36"}, {"access-control-request-headers", "x-requested-with"}, {"accept", "*/*"}
, {"referer", "http://localhost:8081/debugger-ui"}, {"accept-encoding", "gzip, deflate, sdc
h"}, {"accept-language", "en-GB,en-US;q=0.8,en;q=0.6"}], request_path: "/categories", resp_
body: nil, resp_cookies: %{}, resp_headers: [{"cache-control", "max-age=0, private, must-re
validate"}], scheme: :http, script_name: [], secret_key_base: nil, state: :unset, status: n
il}, "OPTIONS", ["categories"], "192.168.20.3")
        (api) lib/api/router.ex:1: Api.Router.plug_builder_call/2
        (api) lib/plug/debugger.ex:123: Api.Router.call/2
        (plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade
/4
        (cowboy) /Users/Ben/Development/Projects/vepo/api/deps/cowboy/src/cowboy_protocol.e
rl:442: :cowboy_protocol.execute/4

一遍又一遍地出现此错误:

17:16:48.032 [error] GenServer #PID<0.332.0> terminating
** (stop) exited in: GenServer.call(Postgrex.TypeManager, {:get, Ecto.Adapters.Postgres.Typ
eModule, {'localhost', 5432, "api_repo"}}, 5000)
    ** (EXIT) time out
    (elixir) lib/gen_server.ex:737: GenServer.call/3
    (postgrex) lib/postgrex/protocol.ex:621: Postgrex.Protocol.bootstrap/3
    (postgrex) lib/postgrex/protocol.ex:475: Postgrex.Protocol.handshake/2
    (db_connection) lib/db_connection/connection.ex:134: DBConnection.Connection.connect/2
    (connection) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol

17:16:48.032 [error] GenServer #PID<0.329.0> terminating
** (stop) exited in: GenServer.call(Postgrex.TypeManager, {:get, Ecto.Adapters.Postgres.Typ
eModule, {'localhost', 5432, "api_repo"}}, 5000)
    ** (EXIT) time out
    (elixir) lib/gen_server.ex:737: GenServer.call/3
    (postgrex) lib/postgrex/protocol.ex:621: Postgrex.Protocol.bootstrap/3
    (postgrex) lib/postgrex/protocol.ex:475: Postgrex.Protocol.handshake/2
    (db_connection) lib/db_connection/connection.ex:134: DBConnection.Connection.connect/2
    (connection) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol

0 个答案:

没有答案