Skip to content

Instantly share code, notes, and snippets.

@Gazler
Last active February 9, 2024 20:43
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gazler/fe7ed5dc598250002dfe to your computer and use it in GitHub Desktop.
Save Gazler/fe7ed5dc598250002dfe to your computer and use it in GitHub Desktop.
defmodule MasterProxy do
use Application
# See http://elixir-lang.org/docs/stable/elixir/Application.html
# for more information on OTP Applications
def start(_type, _args) do
import Supervisor.Spec, warn: false
cowboy = Plug.Adapters.Cowboy.child_spec(:http, MasterProxy.Plug, [])
children = [
cowboy
# Define workers and child supervisors to be supervised
# worker(MasterProxy.Worker, [arg1, arg2, arg3])
]
# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: MasterProxy.Supervisor]
Supervisor.start_link(children, opts)
end
end
defmodule MasterProxy.Mixfile do
use Mix.Project
def project do
[app: :master_proxy,
version: "0.0.1",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.0",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
deps: deps]
end
# Configuration for the OTP application
#
# Type `mix help compile.app` for more information
def application do
[applications: [:logger, :cowboy, :plug, :my_app, :my_app_admin],
mod: {MasterProxy, []}]
end
# Dependencies can be Hex packages:
#
# {:mydep, "~> 0.3.0"}
#
# Or git/path repositories:
#
# {:mydep, git: "https://github.com/elixir-lang/mydep.git", tag: "0.1.0"}
#
# To depend on another app inside the umbrella:
#
# {:myapp, in_umbrella: true}
#
# Type `mix help deps` for more examples and options
defp deps do
[{:my_app_admin, in_umbrella: true},
{:plug, "~> 1.0.0"},
{:cowboy, "~> 1.0.0"},
{:my_app, in_umbrella: true}]
end
end
defmodule MasterProxy.Plug do
import Plug.Conn
def init(options) do
# initialize options
options
end
def call(conn, _opts) do
case some_condition do
foo -> MyApp.Endpoint.call(conn, [])
_ -> MyAppAdmin.Endpoint.call(conn, [])
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment