Skip to content

Commit

Permalink
use Raxx streaming interface from Ace
Browse files Browse the repository at this point in the history
  • Loading branch information
CrowdHailer committed Aug 30, 2017
1 parent 2140211 commit 9804733
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/raxx/blueprint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ defmodule Raxx.Blueprint do

defp path_template_to_match(path_template) do
path_template
|> Raxx.Request.split_path()
|> Raxx.split_path()
|> Enum.map(&template_segment_to_match/1)
end

Expand Down
18 changes: 11 additions & 7 deletions lib/water_cooler/www.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ defmodule WaterCooler.WWW do

EEx.function_from_file(:defp, :home_page, Path.join(__DIR__, "./templates/home_page.html.eex"), [])

def handle_headers(request, config) do
def handle_headers(_request, _config) do
body = home_page()
Raxx.Response.new(:ok, [{"content-type", "text/html"}], body)
Raxx.response(:ok)
|> Raxx.set_header("content-type", "text/html")
|> Raxx.set_body(body)
end
end

Expand All @@ -18,10 +20,11 @@ defmodule WaterCooler.WWW do
alias WaterCooler.ChatRoom
require ChatRoom

def handle_headers(request, config) do
def handle_headers(_request, _config) do
{:ok, _} = ChatRoom.join()
response = Raxx.Response.new(:ok, [{"content-type", "text/event-stream"}], true)
response
Raxx.response(:ok)
|> Raxx.set_header("content-type", "text/event-stream")
|> Raxx.set_body(true)
end

def handle_info(ChatRoom.post(data), config) do
Expand All @@ -36,7 +39,7 @@ defmodule WaterCooler.WWW do
alias WaterCooler.ChatRoom
require ChatRoom

def handle_headers(request, config) do
def handle_headers(_request, _config) do
{[], {:reading, ""}}
end

Expand All @@ -47,7 +50,8 @@ defmodule WaterCooler.WWW do
def handle_trailers([], {:reading, body}) do
{:ok, %{message: message}} = parse_publish_form(body)
{:ok, _} = ChatRoom.publish(message)
response = Raxx.Response.new(303, [{"location", "/"}], false)
Raxx.response(:see_other)
|> Raxx.set_header("location", "/")
end

def parse_publish_form(raw) do
Expand Down

0 comments on commit 9804733

Please sign in to comment.