From c2875a618907cc90aa320e0675a2f3f0e24eb988 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 3 Sep 2018 17:53:31 +0200 Subject: [PATCH] Fix nodeinfo path Signed-off-by: Thomas Citharel --- lib/eventos_web/controllers/nodeinfo_controller.ex | 4 ++-- lib/eventos_web/router.ex | 14 ++++++++++---- .../controllers/nodeinfo_controller_test.exs | 5 +++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/eventos_web/controllers/nodeinfo_controller.ex b/lib/eventos_web/controllers/nodeinfo_controller.ex index b01e3f74f..b2d8eabae 100644 --- a/lib/eventos_web/controllers/nodeinfo_controller.ex +++ b/lib/eventos_web/controllers/nodeinfo_controller.ex @@ -11,7 +11,7 @@ defmodule EventosWeb.NodeinfoController do links: [ %{ rel: "http://nodeinfo.diaspora.software/ns/schema/2.0", - href: EventosWeb.Endpoint.url() <> "/nodeinfo/2.0.json" + href: EventosWeb.Router.Helpers.nodeinfo_url(EventosWeb.Endpoint, :nodeinfo, "2.0") } ] } @@ -20,7 +20,7 @@ defmodule EventosWeb.NodeinfoController do end # Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.0/schema.json - def nodeinfo(conn, %{"version" => "2.0.json"}) do + def nodeinfo(conn, %{"version" => "2.0"}) do import Logger Logger.debug(inspect(@instance)) # stats = Stats.get_stats() diff --git a/lib/eventos_web/router.ex b/lib/eventos_web/router.ex index 75a8a36a2..3e3db2481 100644 --- a/lib/eventos_web/router.ex +++ b/lib/eventos_web/router.ex @@ -30,6 +30,10 @@ defmodule EventosWeb.Router do plug(:put_secure_browser_headers) end + pipeline :nodeinfo do + plug(:accepts, ["html", "application/json"]) + end + scope "/api", EventosWeb do pipe_through(:api) @@ -67,6 +71,12 @@ defmodule EventosWeb.Router do resources("/addresses", AddressController, only: [:index, :show]) get("/search/:name", SearchController, :search) + + scope "/nodeinfo" do + pipe_through(:nodeinfo) + + get("/:version", NodeinfoController, :nodeinfo) + end end end @@ -110,10 +120,6 @@ defmodule EventosWeb.Router do get("/nodeinfo", NodeinfoController, :schemas) end - scope "/nodeinfo", EventosWeb do - get("/:version", NodeinfoController, :nodeinfo) - end - scope "/", EventosWeb do pipe_through(:activity_pub) diff --git a/test/eventos_web/controllers/nodeinfo_controller_test.exs b/test/eventos_web/controllers/nodeinfo_controller_test.exs index b29baa453..d0db93ca5 100644 --- a/test/eventos_web/controllers/nodeinfo_controller_test.exs +++ b/test/eventos_web/controllers/nodeinfo_controller_test.exs @@ -9,7 +9,8 @@ defmodule EventosWeb.NodeinfoControllerTest do assert json_response(conn, 200) == %{ "links" => [ %{ - "href" => EventosWeb.Endpoint.url() <> "/nodeinfo/2.0.json", + "href" => + EventosWeb.Router.Helpers.nodeinfo_url(EventosWeb.Endpoint, :nodeinfo, "2.0"), "rel" => "http://nodeinfo.diaspora.software/ns/schema/2.0" } ] @@ -17,7 +18,7 @@ defmodule EventosWeb.NodeinfoControllerTest do end test "Get node info", %{conn: conn} do - conn = get(conn, nodeinfo_path(conn, :nodeinfo, "2.0.json")) + conn = get(conn, nodeinfo_path(conn, :nodeinfo, "2.0")) resp = json_response(conn, 200)