Skip to content

Instantly share code, notes, and snippets.

@manzanit0
Created June 1, 2021 09:56
Show Gist options
  • Save manzanit0/340d502398f4a713daea5d6efe2264c9 to your computer and use it in GitHub Desktop.
Save manzanit0/340d502398f4a713daea5d6efe2264c9 to your computer and use it in GitHub Desktop.
HTTP Server in elixir w/ shebang
#!/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