From ef4944662cf1442800d5a138fab7d26502c0c69a Mon Sep 17 00:00:00 2001 From: Pierre de Lacroix Date: Tue, 26 May 2020 18:42:57 +0200 Subject: fix use as standalone --- lib/matrix_app_service/application.ex | 10 ++++- lib/matrix_app_service_web/endpoint.ex | 76 +++++++++++++++++----------------- 2 files changed, 47 insertions(+), 39 deletions(-) diff --git a/lib/matrix_app_service/application.ex b/lib/matrix_app_service/application.ex index f3d5803..02d17f2 100644 --- a/lib/matrix_app_service/application.ex +++ b/lib/matrix_app_service/application.ex @@ -16,6 +16,11 @@ defmodule MatrixAppService.Application do # Start a worker by calling: MatrixAppService.Worker.start_link(arg) # {MatrixAppService.Worker, arg} ] + children = if Application.get_env(:matrix_app_service, :standalone, false) do + [MatrixAppServiceWeb.Endpoint | children] + else + children + end # See https://hexdocs.pm/elixir/Supervisor.html # for other strategies and supported options @@ -26,7 +31,10 @@ defmodule MatrixAppService.Application do # Tell Phoenix to update the endpoint configuration # whenever the application is updated. def config_change(changed, _new, removed) do - MatrixAppServiceWeb.Endpoint.config_change(changed, removed) + if Application.get_env(:matrix_app_service, :standalone, false) do + MatrixAppServiceWeb.Endpoint.config_change(changed, removed) + end + :ok end end diff --git a/lib/matrix_app_service_web/endpoint.ex b/lib/matrix_app_service_web/endpoint.ex index 8af15eb..0ee00fc 100644 --- a/lib/matrix_app_service_web/endpoint.ex +++ b/lib/matrix_app_service_web/endpoint.ex @@ -1,45 +1,45 @@ -#defmodule MatrixAppServiceWeb.Endpoint do -# use Phoenix.Endpoint, otp_app: :matrix_app_service +defmodule MatrixAppServiceWeb.Endpoint do + use Phoenix.Endpoint, otp_app: :matrix_app_service -# # The session will be stored in the cookie and signed, -# # this means its contents can be read but not tampered with. -# # Set :encryption_salt if you would also like to encrypt it. -# @session_options [ -# store: :cookie, -# key: "_matrix_app_service_key", -# signing_salt: "zE7AHynD" -# ] + # The session will be stored in the cookie and signed, + # this means its contents can be read but not tampered with. + # Set :encryption_salt if you would also like to encrypt it. + @session_options [ + store: :cookie, + key: "_matrix_app_service_key", + signing_salt: "zE7AHynD" + ] -# socket "/socket", MatrixAppServiceWeb.UserSocket, -# websocket: true, -# longpoll: false + socket "/socket", MatrixAppServiceWeb.UserSocket, + websocket: true, + longpoll: false -# # Serve at "/" the static files from "priv/static" directory. -# # -# # You should set gzip to true if you are running phx.digest -# # when deploying your static files in production. -# plug Plug.Static, -# at: "/", -# from: :matrix_app_service, -# gzip: false, -# only: ~w(css fonts images js favicon.ico robots.txt) + # Serve at "/" the static files from "priv/static" directory. + # + # You should set gzip to true if you are running phx.digest + # when deploying your static files in production. + plug Plug.Static, + at: "/", + from: :matrix_app_service, + gzip: false, + only: ~w(css fonts images js favicon.ico robots.txt) -# # Code reloading can be explicitly enabled under the -# # :code_reloader configuration of your endpoint. -# if code_reloading? do -# plug Phoenix.CodeReloader -# end + # Code reloading can be explicitly enabled under the + # :code_reloader configuration of your endpoint. + if code_reloading? do + plug Phoenix.CodeReloader + end -# plug Plug.RequestId -# plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint] + plug Plug.RequestId + plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint] -# plug Plug.Parsers, -# parsers: [:urlencoded, :multipart, :json], -# pass: ["*/*"], -# json_decoder: Phoenix.json_library() + plug Plug.Parsers, + parsers: [:urlencoded, :multipart, :json], + pass: ["*/*"], + json_decoder: Phoenix.json_library() -# plug Plug.MethodOverride -# plug Plug.Head -# plug Plug.Session, @session_options -# plug MatrixAppServiceWeb.Router -#end + plug Plug.MethodOverride + plug Plug.Head + plug Plug.Session, @session_options + plug MatrixAppServiceWeb.Router +end -- cgit v1.2.3