Created
June 3, 2022 22:39
-
-
Save sheharyarn/38eabea649bfc76947dfbee265064fe5 to your computer and use it in GitHub Desktop.
Simple Elixir Server as a Script
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
Mix.install([{:plug_cowboy, "~> 2.0"}]) | |
defmodule Server do | |
use Plug.Router | |
plug(:match) | |
plug(:dispatch) | |
match _ do | |
send_resp(conn, 200, "Hello World!") | |
end | |
end | |
if System.argv() == ~w[server] do | |
Plug.Cowboy.http(Server, [], port: 4000) | |
System.no_halt(true) | |
end | |
# To install dependencies, just run: elixir app.exs | |
# To start server, run: elixir app.exs server |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment