Skip to content

Commit

Permalink
processes
Browse files Browse the repository at this point in the history
  • Loading branch information
hexisdylan committed Jul 25, 2022
1 parent afc7639 commit 3b10947
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 11 additions & 1 deletion lib/handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Servy.Handler do
alias Servy.Conv
alias Servy.BearController
import Servy.Plugins, only: [rewrite_path: 1, log: 1, track: 1]
import Servy.Parser, only: [parse: 1]
import Servy.Parser, only: [parse: 1]
@moduledoc "Handles HTTP requests."
# @pages_path Path.expand("../pages", __DIR__)
@doc "Transforms the request into a response."
Expand All @@ -20,6 +20,16 @@ import Servy.Parser, only: [parse: 1]
# route(conv, conv.method, conv.path)
# end

def route(%Conv{method: "GET", path: "/kaboom"}) do
raise "Kaboom!"
end

def route(%Conv{method: "GET", path: "/hibernate/" <> time} = conv) do
time |> String.to_integer() |> :timer.sleep()

%{conv | status: 200, resp_body: "Awake!"}
end

def route(%Conv{method: "GET", path: "/wildthings"} = conv) do
%{conv | status: 200, resp_body: "Bears, Lions, Tigers"}
end
Expand Down
4 changes: 3 additions & 1 deletion lib/http_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ defmodule Servy.HttpServer do
IO.puts("⚡️ Connection accepted!\n")

# Receives the request and sends a response over the client socket.
serve(client_socket)
spawn(fn -> serve(client_socket) end)

# Loop back to wait and accept the next connection.
accept_loop(listen_socket)
Expand All @@ -43,6 +43,8 @@ defmodule Servy.HttpServer do
sends a response back over the same socket.
"""
def serve(client_socket) do
IO.puts("#{inspect(self())}: Woking on it!")

client_socket
|> read_request
# |> generate_response
Expand Down

0 comments on commit 3b10947

Please sign in to comment.