git.iko.soy/typeable/servant
on master help sign in
Fix compiler errors in servant-examples.
commitcf59abd2b8072eaad961e57a414830237bf10cd9 authorArian van Putten <aeroboy94@gmail.com> dateFri 2 Oct 2015, 14:12 (11 years ago) parente0fe0a1
2 files changed+38−4
servant-examples/digest-auth/digest-auth.hs+33 servant-examples/tutorial/T9.hs+5−4
servant-examples/digest-auth/digest-auth.hsnew file+33
@@ -0,0 +1,33 @@
1+{-#LANGUAGE DataKinds, TypeOperators, OverloadedStrings #-}
2+module Main where
3+
4+import Data.Text
5+import Data.ByteString (ByteString)
6+import Data.Proxy
7+import Servant.API
8+import Servant.API.Authentication
9+import Servant.Server
10+import Servant.Server.Internal.Authentication
11+import Network.Wai.Handler.Warp
12+
13+
14+data User = User
15+ { username :: ByteString
16+ , ha1 :: ByteString -- ^ MD5(username:realm:password)
17+ }
18+
19+
20+-- | A table with just one user. namely "username:foo:password"
21+table = [("username", User "username" "22f93fe54b9edf660a2f85310adc8a56")]
22+
23+type API = AuthProtect (DigestAuth "foo") User 'Strict :> "foo" :> Get '[JSON] Text
24+
25+api :: Server API
26+api = digestAuthStrict ha1 lookupUser (const . return $ "hello")
27+
28+lookupUser :: DigestAuth "foo" -> IO (Maybe User)
29+lookupUser authData = return . lookup (daUsername authData) $ table
30+
31+
32+main :: IO ()
33+main = run 8080 (serve (Proxy :: Proxy API) api)
servant-examples/tutorial/T9.hs+5−4
@@ -16,6 +16,7 @@ import Servant.JS
1616import System.Random
1717
1818import qualified Data.Text as T
19+import qualified Data.Text.IO as TIO
1920import qualified Language.Javascript.JQuery as JQ
2021
2122data Point = Point
@@ -91,14 +92,14 @@ server' :: Server API'
9192server' = server
9293 :<|> serveDirectory "tutorial/t9"
9394
94−apiJS :: String
95+apiJS :: Text
9596apiJS = jsForAPI api jquery
9697
9798writeJSFiles :: IO ()
9899writeJSFiles = do
99− writeFile "tutorial/t9/api.js" apiJS
100− jq <- readFile =<< JQ.file
101− writeFile "tutorial/t9/jq.js" jq
100+ TIO.writeFile "tutorial/t9/api.js" apiJS
101+ jq <- TIO.readFile =<< JQ.file
102+ TIO.writeFile "tutorial/t9/jq.js" jq
102103
103104app :: Application
104105app = serve api' server'