diff options
author | Kjetil Orbekk <kjetil.orbekk@gmail.com> | 2015-10-09 17:26:57 -0400 |
---|---|---|
committer | Kjetil Orbekk <kjetil.orbekk@gmail.com> | 2015-10-09 17:26:57 -0400 |
commit | 5f737f2ebbd0fdaf5013b8de95e59ab0bd9098f2 (patch) | |
tree | 33d5364c5cfbdeebd4c3b317ded54281ffb6305d | |
parent | 6a044c2b83130fdff1b870ebfd39e2a80edf7738 (diff) |
Include code to pass a request header to servant.
-rwxr-xr-x[-rw-r--r--] | run.sh | 1 | ||||
-rw-r--r-- | src/Main.hs | 9 | ||||
-rw-r--r-- | web/index.html | 15 |
3 files changed, 19 insertions, 6 deletions
@@ -1 +1,2 @@ +#!/bin/bash stack exec photos -- --pending_path=/tmp --photos_path=/tmp diff --git a/src/Main.hs b/src/Main.hs index ba1acd4..3eed3cc 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -20,10 +20,10 @@ import Control.Monad.IO.Class import Control.Monad.Trans.Either defineFlag "port" (8081 :: Int) "Port to serve on" -defineFlag "host" ("*6" :: String) "Host to serve on (*6 for ipv6 mode)" +defineFlag "host" ("*6" :: String) "Host to serve on (*6 for ipv6 mode)" defineFlag "pending_path" ("" :: String) "Path to pending albums" defineFlag "photos_path" ("" :: String) "Path to permanent albums" -$(return []) +$(return []) -- Somehow forces the flags to be set. instance ToJSON Album instance FromJSON Album @@ -38,6 +38,8 @@ instance ToJSON RenameError type PhotoApi = "albums" :> Get '[JSON] [Album] :<|> "rename" :> ReqBody '[JSON] RenameRequest :> Post '[JSON] (Either RenameError ()) + :<|> "test" :> Header "X-Token" String :> Get '[JSON] () +-- Introduce request header containing auth information. config = Config { pendingPath = flags_pending_path @@ -47,6 +49,7 @@ config = Config server :: Server PhotoApi server = albums :<|> rename + :<|> test where albums = liftIO (getAlbums config) @@ -54,6 +57,8 @@ server = albums rename (RenameRequest from to) = liftIO $ runEitherT (renameAlbum config from to) + test token = return () + photoApi :: Proxy PhotoApi photoApi = Proxy diff --git a/web/index.html b/web/index.html index f5ee27c..d1819b0 100644 --- a/web/index.html +++ b/web/index.html @@ -109,10 +109,17 @@ $(document).ready(function() { fetchAlbums(); - var request = { - from: { name: 'x', pending: true }, - to: { name: 'y', pending: false } - }; + $.ajax({ + url: '/api/test', + type: 'GET', + headers: {"X-Token": "foo"}, + success: function(data) { + console.log("Success. got response " + data); + }, + error: function(data) { + console.log("Success. got response " + data); + } + }); }); </script> </head> |