summaryrefslogtreecommitdiff
path: root/Run/Que/Server.hs
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2020-03-31 20:50:14 -0700
committerBen Sima <ben@bsima.me>2020-03-31 20:51:59 -0700
commitcf1d92a7458313b9f3212b6d67958996341e11d4 (patch)
tree12d1ed8cbd72da75f4559e1fcd2f8d56e376c90a /Run/Que/Server.hs
parent744b673f20c6993038e10a480bd746db2c1dccb3 (diff)
Finally fix guardIP
First problem was that my `extract` function wasn't working. Second problem was that nginx wasn't passing along the headers anyway.
Diffstat (limited to 'Run/Que/Server.hs')
-rw-r--r--Run/Que/Server.hs14
1 files changed, 6 insertions, 8 deletions
diff --git a/Run/Que/Server.hs b/Run/Que/Server.hs
index ba7ac86..e0327a5 100644
--- a/Run/Que/Server.hs
+++ b/Run/Que/Server.hs
@@ -28,7 +28,6 @@ import qualified Data.Text.Encoding as Encoding
import Data.Text.Lazy ( Text
, fromStrict
)
-import qualified Data.Text.Lazy as Text
import qualified Network.HTTP.Types.Status as Http
import qualified Network.Socket as Socket
import qualified Network.Wai as Wai
@@ -80,8 +79,8 @@ routes :: Scotty.ScottyT Text App ()
routes = do
Scotty.middleware logStdout
- let quepath = "^/([[:alnum:]_]+)/([[:alnum:]._/]*)$"
- let namespace = "^/([[:alnum:]_]+)/?$" -- matches '/ns' and '/ns/' but not '/ns/path'
+ let quepath = "^\\/([[:alnum:]_]+)\\/([[:alnum:]._/]*)$"
+ let namespace = "^\\/([[:alnum:]_]+)\\/?$" -- matches '/ns' and '/ns/' but not '/ns/path'
-- | GET /index.html
Scotty.get (Scotty.literal "/index.html") <| Scotty.redirect "/_/index"
@@ -112,7 +111,7 @@ routes = do
--
-- Put a value on a que. Returns immediately.
Scotty.post (Scotty.regex quepath) <| do
- r <- Scotty.request
+ r <- Scotty.request
(ns, qp) <- extract
-- "_" is a special, internal namespace that only I can use
when ("_" == ns) <| guardIP r
@@ -158,10 +157,9 @@ insertQue ns qp q as = as { ques = newQues }
extract :: Scotty.ActionT Text App (Namespace, Quepath)
extract = do
- ns <- Scotty.param "0"
- path <- Scotty.param "1"
- let p = Text.split (== '/') path |> filter (not . Text.null)
- return (ns, p)
+ ns <- Scotty.param "1"
+ path <- Scotty.param "2"
+ return (ns, path)
newtype App a = App
{ runApp :: ReaderT (STM.TVar AppState) IO a