Skip to content

Commit d36671f

Browse files
committed
publishing a message
1 parent af92dba commit d36671f

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/watercooler/www.ex

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
defmodule Watercooler.WWW do
22
use Ace.HTTP.Service, [port: 8080, cleartext: true]
3-
3+
44
use Raxx.Router, [
55
{%{method: :GET, path: []}, Watercooler.WWW.HomePage},
6+
{%{method: :POST, path: ["publish"]}, Watercooler.WWW.Publish},
67
{_, Watercooler.WWW.NotFoundPage}
78
]
8-
9+
910
@external_resource "lib/watercooler/public/main.css"
1011
@external_resource "lib/watercooler/public/main.js"
1112
use Raxx.Static, "./public"

lib/watercooler/www/publish.ex

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
defmodule Watercooler.WWW.Publish do
2+
use Raxx.Server
3+
4+
@impl Raxx.Server
5+
def handle_request(request, _state) do
6+
%{"message" => message} =
7+
request.body # 1.
8+
|> URI.decode_www_form()
9+
|> URI.decode_query()
10+
11+
{:ok, _} = Watercooler.publish(message) # 2.
12+
13+
redirect("/") # 3.
14+
end
15+
end

0 commit comments

Comments
 (0)