-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Nested WAI Applications under Scotty Routes (#233)
* nesting apps works * trans instance for nested * don't commit group * ignoring stack * spec added * Changelog entry
- Loading branch information
Showing
9 changed files
with
125 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, beam me up!</h1>"] | ||
|
||
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, beam 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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters