diff options
author | Ben Sima <ben@bsima.me> | 2020-03-30 19:54:15 -0700 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2020-03-30 19:54:15 -0700 |
commit | 6aefe440eb206e2c10b250b15df41f1229073b0b (patch) | |
tree | 8f6c2679708b5ad23cac733718a3326399d407d1 | |
parent | a60a4d3706b748116724cfc365ca925e4ecffd74 (diff) |
Add guarded index route handlers
-rw-r--r-- | Run/Que.hs | 20 |
1 files changed, 19 insertions, 1 deletions
@@ -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 |