Update
This commit is contained in:
parent
a32661e913
commit
3a7c74a67a
22
.gitignore
vendored
Normal file
22
.gitignore
vendored
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
dist
|
||||||
|
dist-*
|
||||||
|
cabal-dev
|
||||||
|
*.o
|
||||||
|
*.hi
|
||||||
|
*.chi
|
||||||
|
*.chs.h
|
||||||
|
*.dyn_o
|
||||||
|
*.dyn_hi
|
||||||
|
.hpc
|
||||||
|
.hsenv
|
||||||
|
.cabal-sandbox/
|
||||||
|
cabal.sandbox.config
|
||||||
|
*.prof
|
||||||
|
*.aux
|
||||||
|
*.hp
|
||||||
|
*.eventlog
|
||||||
|
.stack-work/
|
||||||
|
cabal.project.local
|
||||||
|
cabal.project.local~
|
||||||
|
.HTF/
|
||||||
|
.ghc.environment.*
|
@ -17,9 +17,15 @@ cabal-version: >=1.10
|
|||||||
|
|
||||||
executable scotty-example
|
executable scotty-example
|
||||||
main-is: Main.hs
|
main-is: Main.hs
|
||||||
-- other-modules:
|
other-modules: Helpers
|
||||||
-- other-extensions:
|
-- other-extensions:
|
||||||
build-depends: base >=4.9 && <4.10,
|
build-depends: base >=4.9 && <4.10,
|
||||||
scotty
|
bytestring,
|
||||||
|
scotty,
|
||||||
|
http-types,
|
||||||
|
text,
|
||||||
|
wai,
|
||||||
|
wai-extra,
|
||||||
|
utf8-string
|
||||||
hs-source-dirs: src
|
hs-source-dirs: src
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
|
8
src/Helpers.hs
Normal file
8
src/Helpers.hs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
module Helpers where
|
||||||
|
|
||||||
|
import Data.String
|
||||||
|
|
||||||
|
|
||||||
|
fS :: IsString a => String -> a
|
||||||
|
fS = fromString
|
||||||
|
|
43
src/Main.hs
43
src/Main.hs
@ -1,4 +1,45 @@
|
|||||||
module Main where
|
module Main where
|
||||||
|
|
||||||
|
import Web.Scotty
|
||||||
|
|
||||||
|
import Data.Monoid (mconcat)
|
||||||
|
import Helpers
|
||||||
|
import Network.HTTP.Types.Status
|
||||||
|
import qualified Data.Text.Lazy as T
|
||||||
|
import Network.Wai
|
||||||
|
import Network.Wai.Middleware.RequestLogger
|
||||||
|
import Network.Wai.Middleware.HttpAuth
|
||||||
|
import qualified Data.ByteString as BS
|
||||||
|
import qualified Data.ByteString.UTF8 as U8
|
||||||
|
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = putStrLn "Hello, Haskell!"
|
main = scotty 3000 $ do
|
||||||
|
middleware auth
|
||||||
|
middleware logging
|
||||||
|
get (fS "/foo") foo
|
||||||
|
get (fS "/:word") word_pattern
|
||||||
|
|
||||||
|
|
||||||
|
word_pattern :: ActionM ()
|
||||||
|
word_pattern = do
|
||||||
|
beam <- param (fS "word")
|
||||||
|
html $ mconcat [fS "<h1>Scotty, ", beam, fS " me up!</h1>"]
|
||||||
|
|
||||||
|
|
||||||
|
foo :: ActionM ()
|
||||||
|
foo = do
|
||||||
|
status ok200
|
||||||
|
text $ T.pack "Blah"
|
||||||
|
return ()
|
||||||
|
|
||||||
|
|
||||||
|
logging :: Middleware
|
||||||
|
logging = logStdout
|
||||||
|
|
||||||
|
|
||||||
|
auth :: Middleware
|
||||||
|
auth = basicAuth (\u p -> return $
|
||||||
|
u == U8.fromString "michael" &&
|
||||||
|
p == U8.fromString "mypass")
|
||||||
|
(fS "My Realm")
|
||||||
|
Loading…
Reference in New Issue
Block a user