Skip to content

Commit

Permalink
publishing a message
Browse files Browse the repository at this point in the history
  • Loading branch information
CrowdHailer committed May 28, 2018
1 parent af92dba commit d36671f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/watercooler/www.ex
Original file line number Original file line Diff line number Diff line change
@@ -1,11 +1,12 @@
defmodule Watercooler.WWW do defmodule Watercooler.WWW do
use Ace.HTTP.Service, [port: 8080, cleartext: true] use Ace.HTTP.Service, [port: 8080, cleartext: true]

use Raxx.Router, [ use Raxx.Router, [
{%{method: :GET, path: []}, Watercooler.WWW.HomePage}, {%{method: :GET, path: []}, Watercooler.WWW.HomePage},
{%{method: :POST, path: ["publish"]}, Watercooler.WWW.Publish},
{_, Watercooler.WWW.NotFoundPage} {_, Watercooler.WWW.NotFoundPage}
] ]

@external_resource "lib/watercooler/public/main.css" @external_resource "lib/watercooler/public/main.css"
@external_resource "lib/watercooler/public/main.js" @external_resource "lib/watercooler/public/main.js"
use Raxx.Static, "./public" use Raxx.Static, "./public"
Expand Down
15 changes: 15 additions & 0 deletions lib/watercooler/www/publish.ex
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,15 @@
defmodule Watercooler.WWW.Publish do
use Raxx.Server

@impl Raxx.Server
def handle_request(request, _state) do
%{"message" => message} =
request.body # 1.
|> URI.decode_www_form()
|> URI.decode_query()

{:ok, _} = Watercooler.publish(message) # 2.

redirect("/") # 3.
end
end

0 comments on commit d36671f

Please sign in to comment.