diff options
author | Ben Sima <ben@bsima.me> | 2020-03-31 20:50:14 -0700 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2020-03-31 20:51:59 -0700 |
commit | cf1d92a7458313b9f3212b6d67958996341e11d4 (patch) | |
tree | 12d1ed8cbd72da75f4559e1fcd2f8d56e376c90a | |
parent | 744b673f20c6993038e10a480bd746db2c1dccb3 (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.
-rw-r--r-- | Run/Que/Server.hs | 14 | ||||
-rw-r--r-- | Run/Que/service.nix | 4 |
2 files changed, 10 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 diff --git a/Run/Que/service.nix b/Run/Que/service.nix index b9f5c19..1d82bd6 100644 --- a/Run/Que/service.nix +++ b/Run/Que/service.nix @@ -60,6 +60,10 @@ in enableACME = true; locations."/" = { proxyPass = "http://localhost:${toString cfg.port}"; + extraConfig = '' + # forward the headers so the `guardIP` function works properly + proxy_pass_request_headers on; + ''; }; }; }; |