Permalink
Browse files

publishing a message

  • Loading branch information...
CrowdHailer committed May 28, 2018
1 parent af92dba commit d36671f052fc6690943de6227bb0c39e281311d2
Showing with 18 additions and 2 deletions.
  1. +3 −2 lib/watercooler/www.ex
  2. +15 −0 lib/watercooler/www/publish.ex
View
@@ -1,11 +1,12 @@
defmodule Watercooler.WWW do
use Ace.HTTP.Service, [port: 8080, cleartext: true]
use Raxx.Router, [
{%{method: :GET, path: []}, Watercooler.WWW.HomePage},
{%{method: :POST, path: ["publish"]}, Watercooler.WWW.Publish},
{_, Watercooler.WWW.NotFoundPage}
]
@external_resource "lib/watercooler/public/main.css"
@external_resource "lib/watercooler/public/main.js"
use Raxx.Static, "./public"
@@ -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.