-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: reimplement functionality originally provided by trot
- Loading branch information
Showing
35 changed files
with
463 additions
and
372 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
[inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]] | ||
[ | ||
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"], | ||
locals_without_parens: [aar: 1], | ||
import_deps: [:plug] | ||
] |
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 |
---|---|---|
@@ -1,12 +1,10 @@ | ||
import Config | ||
import System | ||
|
||
config :trot, | ||
port: get_env("PORT"), | ||
pre_routing: [ | ||
"Elixir.Plug.SSL": [rewrite_on: [:x_forwarded_proto]], | ||
"Elixir.PlugHeartbeat": [], | ||
"Elixir.Plug.Static": [at: "/", from: :asapi], | ||
"Elixir.Asapi.Library": [], | ||
"Elixir.Asapi.Type": [] | ||
] | ||
try do | ||
System.get_env("PORT") | ||
|> String.to_integer() | ||
rescue | ||
_ -> nil | ||
else | ||
port -> config :asapi, port: port | ||
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
erlang_version=24.3 | ||
elixir_version=1.13.3 | ||
erlang_version=25.3 | ||
elixir_version=1.14.4 |
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 |
---|---|---|
@@ -1,35 +1,21 @@ | ||
# Copyright 2017 Christian Schmitz | ||
# Copyright 2023 Christian Schmitz | ||
# SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
defmodule Asapi do | ||
@loading "…" | ||
@unknown "unknown" | ||
use Application | ||
|
||
def shield(status, json \\ false) when status in [@loading, @unknown] do | ||
shield(status, "inactive", json) | ||
end | ||
|
||
def shield(status, json) do | ||
shield(status, "informational", json) | ||
end | ||
@impl true | ||
def start(_type, _args) do | ||
cowboy_options = [ | ||
compress: true, | ||
port: Application.get_env(:asapi, :port, 4000) | ||
] | ||
|
||
defp shield(status, color, json) do | ||
unless json do | ||
"https://img.shields.io/badge/API-#{encode(status)}-#{color}" | ||
else | ||
"{\"schemaVersion\":1,\"label\":\"API\",\"message\":\"#{status}\",\"color\":\"#{color}\"}" | ||
end | ||
end | ||
|
||
defp encode(part) do | ||
String.replace(part, "-", "--") | ||
end | ||
children = [ | ||
Asapi.Ext, | ||
{Plug.Cowboy, scheme: :http, plug: Asapi.Router, options: cowboy_options} | ||
] | ||
|
||
defmacro __using__(_) do | ||
quote do | ||
import Asapi | ||
@loading unquote(@loading) | ||
@unknown unquote(@unknown) | ||
end | ||
Supervisor.start_link(children, strategy: :one_for_one) | ||
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
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
Oops, something went wrong.