-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Reorganize archethic_web folders * Reorganize archetic_web_test folders * Rename archethic_web modules * Rework archethic web routers * Refactor API folder * Add error control in router_dispatch
- Loading branch information
Showing
149 changed files
with
643 additions
and
558 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
defmodule ArchethicWeb.AEWeb do | ||
@moduledoc false | ||
|
||
def controller do | ||
quote do | ||
use Phoenix.Controller, namespace: ArchethicWeb.AEWeb | ||
|
||
import Plug.Conn | ||
end | ||
end | ||
|
||
def view do | ||
quote do | ||
use Phoenix.View, | ||
root: "lib/archethic_web/aeweb/templates", | ||
namespace: ArchethicWeb.AEWeb | ||
|
||
# Import convenience functions from controllers | ||
import Phoenix.Controller, only: [get_flash: 1, get_flash: 2, view_module: 1] | ||
import ArchethicWeb.WebUtils | ||
# Import basic rendering functionality (render, render_layout, etc) | ||
import Phoenix.View | ||
end | ||
end | ||
|
||
def router do | ||
quote do | ||
use Phoenix.Router | ||
import Phoenix.Controller | ||
end | ||
end | ||
|
||
@doc """ | ||
When used, dispatch to the appropriate controller/view/etc. | ||
""" | ||
defmacro __using__(which) when is_atom(which) do | ||
apply(__MODULE__, which, []) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
defmodule ArchethicWeb.AEWebRouter do | ||
@moduledoc false | ||
use ArchethicWeb.AEWeb, :router | ||
|
||
alias ArchethicWeb.AEWeb.WebHostingController | ||
|
||
alias ArchethicWeb.Plug.ThrottleByIPHigh | ||
alias ArchethicWeb.Plug.ThrottleByIPandPath | ||
|
||
pipeline :browser do | ||
plug(:accepts, ["html"]) | ||
plug(:put_secure_browser_headers) | ||
plug(ThrottleByIPHigh) | ||
plug(ThrottleByIPandPath) | ||
end | ||
|
||
scope "/aeweb" do | ||
pipe_through(:browser) | ||
|
||
get("/:address/*url_path", WebHostingController, :web_hosting) | ||
end | ||
|
||
scope "/api/web_hosting" do | ||
pipe_through(:browser) | ||
|
||
get("/:address/*url_path", WebHostingController, :web_hosting) | ||
end | ||
end |
14 changes: 6 additions & 8 deletions
14
...controllers/api/web_hosting_controller.ex → ...web/controllers/web_hosting_controller.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...sting_controller/reference_transaction.ex → ...sting_controller/reference_transaction.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...s/api/web_hosting_controller/resources.ex → ...llers/web_hosting_controller/resources.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
defmodule ArchethicWeb.DNSLinkRouter do | ||
@moduledoc """ | ||
Catch dns link redirection for AEWeb and call WebHostingController | ||
""" | ||
|
||
alias ArchethicWeb.AEWeb.Domain | ||
alias ArchethicWeb.AEWeb.WebHostingController | ||
|
||
@behaviour Plug | ||
|
||
def init(opts), do: opts | ||
|
||
def call(conn = %Plug.Conn{host: host, method: "GET", path_info: url_path}, _) do | ||
case get_dnslink_address(host) do | ||
{:ok, address} -> | ||
WebHostingController.web_hosting(conn, %{"address" => address, "url_path" => url_path}) | ||
|
||
_ -> | ||
throw("No DNSLink defined") | ||
end | ||
end | ||
|
||
def call(_conn, _), do: throw("No DNSLink defined") | ||
|
||
defp get_dnslink_address(host) do | ||
if is_ip_address?(host), do: {:error, :ip_address}, else: Domain.lookup_dnslink_address(host) | ||
end | ||
|
||
defp is_ip_address?(host), | ||
do: {:ok, _ip} |> match?(host |> String.to_charlist() |> :inet.parse_address()) | ||
end |
5 changes: 3 additions & 2 deletions
5
lib/archethic_web/domain.ex → lib/archethic_web/aeweb/domain.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
lib/archethic_web/views/dir_listing_view.ex → ...ethic_web/aeweb/views/dir_listing_view.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
defmodule ArchethicWeb.API do | ||
@moduledoc false | ||
|
||
def controller do | ||
quote do | ||
use Phoenix.Controller, namespace: ArchethicWeb.API | ||
|
||
import Plug.Conn | ||
end | ||
end | ||
|
||
def router do | ||
quote do | ||
use Phoenix.Router | ||
import Plug.Conn | ||
end | ||
end | ||
|
||
@doc """ | ||
When used, dispatch to the appropriate controller/view/etc. | ||
""" | ||
defmacro __using__(which) when is_atom(which) do | ||
apply(__MODULE__, which, []) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
defmodule ArchethicWeb.APIRouter do | ||
@moduledoc false | ||
|
||
alias ArchethicWeb.API | ||
alias ArchethicWeb.Plug.ThrottleByIPLow | ||
|
||
use ArchethicWeb.Explorer, :router | ||
|
||
pipeline :api do | ||
plug(:accepts, ["json"]) | ||
plug(ThrottleByIPLow) | ||
plug(ArchethicWeb.API.GraphQL.Context) | ||
end | ||
|
||
scope "/api", API do | ||
pipe_through(:api) | ||
|
||
get("/last_transaction/:address/content", TransactionController, :last_transaction_content) | ||
|
||
post("/origin_key", OriginKeyController, :origin_key) | ||
post("/transaction", TransactionController, :new) | ||
post("/transaction_fee", TransactionController, :transaction_fee) | ||
|
||
post("/transaction/contract/simulator", TransactionController, :simulate_contract_execution) | ||
end | ||
|
||
scope "/api" do | ||
pipe_through(:api) | ||
|
||
forward( | ||
"/graphiql", | ||
Absinthe.Plug.GraphiQL, | ||
schema: ArchethicWeb.API.GraphQL.Schema, | ||
socket: ArchethicWeb.UserSocket | ||
) | ||
|
||
forward( | ||
"/", | ||
Absinthe.Plug, | ||
schema: ArchethicWeb.API.GraphQL.Schema | ||
) | ||
end | ||
end |
Oops, something went wrong.