Created
June 1, 2021 09:56
-
-
Save manzanit0/340d502398f4a713daea5d6efe2264c9 to your computer and use it in GitHub Desktop.
HTTP Server in elixir w/ shebang
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
#!/usr/bin/env elixir | |
Mix.install([ | |
{:plug_cowboy, "~> 2.5"} | |
]) | |
defmodule Router do | |
use Plug.Router | |
plug(Plug.Logger) | |
plug(:match) | |
plug(:dispatch) | |
get "/" do | |
send_resp(conn, 200, "Hello, World!") | |
end | |
match _ do | |
send_resp(conn, 404, "not found") | |
end | |
end | |
plug_cowboy = {Plug.Cowboy, plug: Router, scheme: :http, port: 4000} | |
require Logger | |
Logger.info("starting #{inspect(plug_cowboy)}") | |
{:ok, _} = Supervisor.start_link([plug_cowboy], strategy: :one_for_one) | |
Process.sleep(:infinity) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment