s-m-i-t-a / argo

A small web framework.
0 stars 0 forks source link

Create redirect function #3

Closed s-m-i-t-a closed 5 years ago

s-m-i-t-a commented 5 years ago

Same functionality as Phoenix.Controller.redirect/2.

bultas commented 5 years ago

we want shortcut for:

conn
    |> Conn.put_resp_header("location", "http://www.example.com")
    |> Conn.send_resp(302, "Redirect")
bultas commented 5 years ago

problem with endpoint pipe without render() in the end

[error] #PID<0.1488.0> running Server.Web.Endpoint (connection #PID<0.1486.0>, stream id 1) terminated
Server: chilly-dust.localhost:4000 (http)
Request: POST /
** (exit) an exception was raised:
    ** (FunctionClauseError) no function clause matching in Argo.View.render/2
        (argo) lib/argo/view.ex:27: Argo.View.render(%Plug.Conn{adapter: {Plug.Cowboy.Conn, :...}, assigns: %{data: %{app: %{static_url: "http://chilly-dust.localhost:4000/static"}, config: %{api_url: "http://localhost:4000/api"}, page: %Pages.Page{__meta__: #Ecto.Schema.Metadata<:loaded, "pages">, app: %Apps.App{name: "cc_account"}, db: %{}, domain: nil, id: 8, inserted_at: ~N[2019-07-20 09:46:00], name: "New Page", owner: #Ecto.Association.NotLoaded<association :owner is not loaded>, owner_id: 1, slug: "chilly-dust", updated_at: ~N[2019-08-05 09:28:22]}}, page: %Pages.Page{__meta__: #Ecto.Schema.Metadata<:loaded, "pages">, app: %Apps.App{name: "cc_account"}, db: %{}, domain: nil, id: 8, inserted_at: ~N[2019-07-20 09:46:00], name: "New Page", owner: #Ecto.Association.NotLoaded<association :owner is not loaded>, owner_id: 1, slug: "chilly-dust", updated_at: ~N[2019-08-05 09:28:22]}}, before_send: [#Function<2.10850643/1 in Phoenix.Controller.fetch_flash/2>, #Function<0.35161479/1 in Plug.Session.before_send/2>, #Function<1.16531471/1 in Plug.Logger.call/2>, #Function<0.50969320/1 in Phoenix.LiveReloader.before_send_inject_reloader/2>], body_params: %{"email" => "comm3net@gmail.com", "password" => "12345678"}, cookies: %{}, halted: false, host: "chilly-dust.localhost", method: "POST", owner: #PID<0.1488.0>, params: %{"email" => "comm3net@gmail.com", "password" => "12345678", "rest" => []}, path_info: [], path_params: %{"rest" => []}, port: 4000, private: %{Server.Web.Router => {[], %{}}, :phoenix_action => :index, :phoenix_controller => Server.Web.PageController, :phoenix_endpoint => Server.Web.Endpoint, :phoenix_flash => %{}, :phoenix_format => "html", :phoenix_layout => {Server.Web.LayoutView, :app}, :phoenix_router => Server.Web.Router, :phoenix_view => Server.Web.PageView, :plug_route => {"/", #Function<1.19943584/2 in CCAccount.Router.do_match/4>}, :plug_session => %{}, :plug_session_fetch => :done}, query_params: %{}, query_string: "", remote_ip: {127, 0, 0, 1}, req_cookies: %{}, req_headers: [{"accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3"}, {"accept-encoding", "gzip, deflate, br"}, {"accept-language", "cs-CZ,cs;q=0.9,en;q=0.8,es;q=0.7"}, {"cache-control", "max-age=0"}, {"connection", "keep-alive"}, {"content-length", "44"}, {"content-type", "application/x-www-form-urlencoded"}, {"host", "chilly-dust.localhost:4000"}, {"origin", "http://chilly-dust.localhost:4000"}, {"referer", "http://chilly-dust.localhost:4000/"}, {"upgrade-insecure-requests", "1"}, {"user-agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36"}], request_path: "/", resp_body: nil, resp_cookies: %{}, resp_headers: [{"cache-control", "max-age=0, private, must-revalidate"}, {"x-request-id", "FbgITCLu5pBrZNAAACNh"}, {"access-control-allow-origin", "*"}, {"access-control-expose-headers", ""}, {"access-control-allow-credentials", "true"}, {"x-frame-options", "SAMEORIGIN"}, {"x-xss-protection", "1; mode=block"}, {"x-content-type-options", "nosniff"}, {"x-download-options", "noopen"}, {"x-permitted-cross-domain-policies", "none"}, {"cross-origin-window-policy", "deny"}, {"location", "http://www.seznam.cz"}], scheme: :http, script_name: [], secret_key_base: :..., state: :sent, status: 302}, CCAccount.PagesView)
        (argo) lib/argo/router.ex:68: Argo.Router.process/3
        (cc_account) lib/plug/router.ex:259: CCAccount.Router.dispatch/2
        (cc_account) lib/cc_account/router.ex:1: CCAccount.Router.plug_builder_call/2
        (server) lib/server/web/controllers/page_controller.ex:1: Server.Web.PageController.action/2
        (server) lib/server/web/controllers/page_controller.ex:1: Server.Web.PageController.phoenix_controller_pipeline/2
        (phoenix) lib/phoenix/router.ex:288: Phoenix.Router.__call__/2
        (server) lib/server/web/endpoint.ex:1: Server.Web.Endpoint.plug_builder_call/2
        (server) lib/server/web/endpoint.ex:1: Server.Web.Endpoint.call/2
        (phoenix) lib/phoenix/endpoint/cowboy2_handler.ex:40: Phoenix.Endpoint.Cowboy2Handler.init/2
        (cowboy) /Users/bultas/Work/projects/pages/new/server/deps/cowboy/src/cowboy_handler.erl:41: :cowboy_handler.execute/2
        (cowboy) /Users/bultas/Work/projects/pages/new/server/deps/cowboy/src/cowboy_stream_h.erl:296: :cowboy_stream_h.execute/3
        (cowboy) /Users/bultas/Work/projects/pages/new/server/deps/cowboy/src/cowboy_stream_h.erl:274: :cowboy_stream_h.request_process/3
        (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3