Skip to content

Commit

Permalink
Dynamically redirect UI requests
Browse files Browse the repository at this point in the history
  • Loading branch information
jjcarstens committed May 28, 2020
1 parent 5bf2beb commit d5bb107
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/vintage_net_wizard/web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defmodule VintageNetWizard.Web.Router do
get "/" do
case BackendServer.configurations() do
[] ->
redirect(conn, "/networks")
redirect(conn, Path.join(conn.request_path, "/networks"))

configs ->
render_page(conn, "index.html",
Expand All @@ -38,7 +38,9 @@ defmodule VintageNetWizard.Web.Router do
case WiFiConfiguration.from_params(params) do
{:ok, wifi_config} ->
:ok = BackendServer.save(wifi_config)
redirect(conn, "/")

[path | _] = String.split(conn.request_path, "/ssid/")
redirect(conn, path)

error ->
{:ok, key_mgmt} = WiFiConfiguration.key_mgmt_from_string(conn.body_params["key_mgmt"])
Expand Down Expand Up @@ -101,7 +103,8 @@ defmodule VintageNetWizard.Web.Router do
"none" ->
{:ok, config} = WiFiConfiguration.from_params(conn.body_params)
:ok = BackendServer.save(config)
redirect(conn, "/")
[path | _] = String.split(conn.request_path, "/networks/")
redirect(conn, path)

key_mgmt ->
key_mgmt = String.to_existing_atom(key_mgmt)
Expand Down

0 comments on commit d5bb107

Please sign in to comment.