Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .credo.exs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
# If you want to enforce a style guide and need a more traditional linting
# experience, you can change `strict` to `true` below:
#
strict: true, # false,
strict: true,
#
# To modify the timeout for parsing files, change this value:
#
Expand Down
3 changes: 3 additions & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}", "priv/*/seeds.exs"]
]
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# FunWithFlags.UI

[![Mix Tests](https://github.com/tompave/fun_with_flags_ui/workflows/Mix%20Tests/badge.svg)](https://github.com/tompave/fun_with_flags_ui/actions?query=branch%3Amaster)
[![Code Quality](https://github.com/tompave/fun_with_flags_ui/actions/workflows/quality.yml/badge.svg?branch=master)](https://github.com/tompave/fun_with_flags_ui/actions/workflows/quality.yml?query=branch%3Amaster)
[![Code Quality](https://github.com/tompave/fun_with_flags_ui/actions/workflows/quality.yml/badge.svg?branch=master)](https://github.com/tompave/fun_with_flags_ui/actions/workflows/quality.yml?query=branch%3Amaster)
[![Hex.pm](https://img.shields.io/hexpm/v/fun_with_flags_ui.svg)](https://hex.pm/packages/fun_with_flags_ui)

A Web dashboard for the [FunWithFlags](https://github.com/tompave/fun_with_flags) Elixir package.
Expand Down Expand Up @@ -56,7 +56,7 @@ Again, because it's just a plug, it can be run [standalone](https://hexdocs.pm/p
If you clone the repository, the library comes with two convenience functions to accomplish this:

```elixir
# Simple, let Cowboy sort out the supervision tree:
# Simple, let Bandit sort out the supervision tree:
{:ok, pid} = FunWithFlags.UI.run_standalone()

# Uses some explicit supervision configuration:
Expand Down Expand Up @@ -115,7 +115,7 @@ For this reason this library enforces some stricter rules when creating flags an

## Installation

The package can be installed by adding `fun_with_flags_ui` to your list of dependencies in `mix.exs`.
The package can be installed by adding `fun_with_flags_ui` to your list of dependencies in `mix.exs`.
It requires [`fun_with_flags`](https://hex.pm/packages/fun_with_flags), see its [installation documentation](https://github.com/tompave/fun_with_flags#installation) for more details.

```elixir
Expand Down
5 changes: 5 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
redis:
image: redis:8
ports:
- "6379:6379"
2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ config :fun_with_flags, :cache_bust_notifications, enabled: false

case config_env() do
:test -> import_config "test.exs"
_ -> nil
_ -> nil
end
35 changes: 18 additions & 17 deletions lib/fun_with_flags/ui.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,49 @@ defmodule FunWithFlags.UI do

@doc false
def start(_type, _args) do
check_cowboy()
check_bandit()

children = [
{Plug.Cowboy, scheme: :http, plug: FunWithFlags.UI.Router, options: [port: 8080]}
{Bandit, scheme: :http, plug: FunWithFlags.UI.Router, options: [port: 8080]}
]

opts = [strategy: :one_for_one, name: FunWithFlags.UI.Supervisor]
Supervisor.start_link(children, opts)
end


# Since :cowboy is an optional dependency, if we want to run this
# standalone we want to return a clear error message if Cowboy is
# Since :bandit is an optional dependency, if we want to run this
# standalone we want to return a clear error message if Bandit is
# missing.
#
# On the other hand, if :fun_with_flags_ui is run as a Plug in a
# host application, we don't really care about this dependency
# here, as the responsibility of managing the HTTP layer belongs
# to the host app.
#
defp check_cowboy do
with :ok <- Application.ensure_started(:ranch),
:ok <- Application.ensure_started(:cowlib),
:ok <- Application.ensure_started(:cowboy) do
:ok
else
defp check_bandit do
case Application.ensure_started(:bandit) do
:ok ->
:ok

{:error, _} ->
raise "You need to add :cowboy to your Mix dependencies to run FunWithFlags.UI standalone."
raise "You need to add :bandit to your Mix dependencies to run FunWithFlags.UI standalone."
end
end


@doc """
Convenience function to simply run the Plug in Cowboy.
Convenience function to simply run the Plug in Bandit.

This _will_ be supervided, but in the private supervsion tree
of :cowboy and :ranch.
of :bandit.
"""
def run_standalone do
Plug.Cowboy.http FunWithFlags.UI.Router, [], port: 8080
end
server_opts = [
plug: FunWithFlags.UI.Router,
port: 8080
]

Bandit.start_link(server_opts)
end

@doc """
Convenience function to run the Plug in a custom supervision tree.
Expand Down
Loading