Last active
December 10, 2020 15:13
-
-
Save TylerPachal/5c9f9e5844ac490533a0f84aa46ce3e1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| defmodule Api do | |
| require Record | |
| # Wrap the Erlang Record to make the request_uri parameter easier to access | |
| Record.defrecord :httpd, Record.extract(:mod, from_lib: "inets/include/httpd.hrl") | |
| def child_spec(_) do | |
| opts = [ | |
| server_name: 'Api', | |
| server_root: '/tmp', | |
| document_root: '/tmp', | |
| port: 3000, | |
| modules: [__MODULE__] | |
| ] | |
| args = [:httpd, opts] | |
| %{ | |
| id: make_ref(), | |
| start: {:inets, :start, args} | |
| } | |
| end | |
| def unquote(:do)(data) do | |
| response = | |
| case httpd(data, :request_uri) do | |
| '/' -> | |
| if is_healthy?() do | |
| {200, 'I am healthy'} | |
| else | |
| {503, 'I am unhealthy'} | |
| end | |
| _ -> {404, 'Not found'} | |
| end | |
| {:proceed, [response: response]} | |
| end | |
| defp is_healthy?() do | |
| # Checks some of the other processes | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment