-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nested WAI Applications under Scotty Routes #233
Changes from 5 commits
9d8e1d6
1d2846d
8bd9ed8
bd00dcf
c2184bb
0898720
68543af
5fcd45d
1358e6f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,6 @@ cabal.project.local | |
cabal.project.local~ | ||
.HTF/ | ||
.ghc.environment.* | ||
stack.yaml | ||
stack.yaml.lock | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
module Main where | ||
|
||
import Web.Scotty | ||
import Network.Wai | ||
import qualified Data.Text.Lazy as TL | ||
import Network.HTTP.Types.Status | ||
import Data.Monoid (mconcat) | ||
|
||
simpleApp :: Application | ||
simpleApp _ respond = do | ||
putStrLn "I've done some IO here" | ||
respond $ responseLBS | ||
status200 | ||
[("Content-Type", "text/plain")] | ||
"Hello, Web!" | ||
|
||
scottApp :: IO Application | ||
scottApp = scottyApp $ do | ||
|
||
get "/" $ do | ||
html $ mconcat ["<h1>Scotty, bean me up!</h1>"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bean There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😆 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ocramz updated to beam |
||
|
||
get "/other/test/:word" $ do | ||
beam <- param "word" | ||
html $ mconcat ["<h1>Scotty, ", beam, " me up!</h1>"] | ||
|
||
get "/test/:word" $ do | ||
beam <- param "word" | ||
html $ mconcat ["<h1>Scotty, ", beam, " me up!</h1>"] | ||
|
||
get "/nested" $ nested simpleApp | ||
get "/other/nested" $ nested simpleApp | ||
|
||
notFound $ do | ||
r <- request | ||
html (TL.pack (show (pathInfo r))) | ||
|
||
-- For example, returns path info: ["other","qwer","adxf","jkashdfljhaslkfh","qwer"] | ||
-- for request http://localhost:3000/other/qwer/adxf/jkashdfljhaslkfh/qwer | ||
|
||
main :: IO () | ||
main = do | ||
|
||
otherApp <- scottApp | ||
|
||
scotty 3000 $ do | ||
|
||
get "/" $ do | ||
html $ mconcat ["<h1>Scotty, bean me up!</h1>"] | ||
|
||
get "/test/:word" $ do | ||
beam <- param "word" | ||
html $ mconcat ["<h1>Scotty, ", beam, " me up!</h1>"] | ||
|
||
get "/simple" $ nested simpleApp | ||
|
||
get "/other" $ nested otherApp | ||
|
||
get (regex "/other/.*") $ nested otherApp | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this catch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems 'app' could put a landmine inside the MVar so.. I think so?