summaryrefslogtreecommitdiff
path: root/Run/Que.hs
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2020-03-30 19:54:15 -0700
committerBen Sima <ben@bsima.me>2020-03-30 19:54:15 -0700
commit6aefe440eb206e2c10b250b15df41f1229073b0b (patch)
tree8f6c2679708b5ad23cac733718a3326399d407d1 /Run/Que.hs
parenta60a4d3706b748116724cfc365ca925e4ecffd74 (diff)
Add guarded index route handlers
Diffstat (limited to 'Run/Que.hs')
-rw-r--r--Run/Que.hs20
1 files changed, 19 insertions, 1 deletions
diff --git a/Run/Que.hs b/Run/Que.hs
index 9893af2..356584f 100644
--- a/Run/Que.hs
+++ b/Run/Que.hs
@@ -82,6 +82,24 @@ routes = do
Scotty.middleware logStdoutDev
let quepath = "^/([[:alnum:]_]*)/([[:alnum:]_/]*)$"
+ let index = "^(/|/index.html)$"
+
+ Scotty.get (Scotty.regex index) <| do
+ let (ns, qp) = ("_", ["index"])
+ app . modify <| upsertNamespace ns
+ q <- app <| que ns qp
+ r <- liftIO <| takeQue q
+ Scotty.html <| fromStrict <| Encoding.decodeUtf8 r
+
+ Scotty.post (Scotty.regex index) <| do
+ r <- Scotty.request
+ guardIP r
+ let (ns, qp) = ("_", ["index"])
+ app . modify <| upsertNamespace ns
+ q <- app <| que ns qp
+ qdata <- Scotty.body
+ liftIO <| pushQue (BSL.toStrict qdata) q
+ return ()
Scotty.matchAny (Scotty.regex "^/([[:alnum:]_]*)/?$") <| do
-- matches '/ns' and '/ns/' but not '/ns/path'
@@ -101,7 +119,7 @@ routes = do
True -> Scotty.stream $ streamQue q
_ -> do
r <- liftIO <| takeQue q
- Scotty.text <| fromStrict <| Encoding.decodeUtf8 r
+ Scotty.html <| fromStrict <| Encoding.decodeUtf8 r
-- | Put a value on a que. Returns immediately.
Scotty.post (Scotty.regex quepath) <| do