From 6aefe440eb206e2c10b250b15df41f1229073b0b Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Mon, 30 Mar 2020 19:54:15 -0700 Subject: Add guarded index route handlers --- Run/Que.hs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'Run') 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 -- cgit v1.2.3