Built in function for statics from dir
This commit is contained in:
parent
7df28f4f30
commit
5231da57a3
1
TODO
1
TODO
@ -1,3 +1,4 @@
|
||||
Catch exceptions and return as 500 errors
|
||||
approot
|
||||
Request parameters without a request object?
|
||||
More checking on parameters (minimum length etc)
|
||||
|
||||
@ -16,14 +16,26 @@
|
||||
module Web.Restful.Helpers.Static
|
||||
( serveStatic
|
||||
, FileLookup
|
||||
, fileLookupDir
|
||||
) where
|
||||
|
||||
import qualified Data.ByteString as B
|
||||
import System.Directory (doesFileExist)
|
||||
import Control.Applicative ((<$>))
|
||||
|
||||
import Web.Restful
|
||||
|
||||
type FileLookup = FilePath -> IO (Maybe B.ByteString)
|
||||
|
||||
-- | A 'FileLookup' for files in a directory.
|
||||
fileLookupDir :: FilePath -> FileLookup
|
||||
fileLookupDir dir fp = do
|
||||
let fp' = dir ++ '/' : fp -- FIXME incredibly insecure...
|
||||
exists <- doesFileExist fp'
|
||||
if exists
|
||||
then Just <$> B.readFile fp'
|
||||
else return Nothing
|
||||
|
||||
serveStatic :: FileLookup -> Verb -> Handler
|
||||
serveStatic fl Get = getStatic fl
|
||||
serveStatic _ _ = notFound
|
||||
|
||||
@ -36,7 +36,8 @@ library
|
||||
test-framework-hunit,
|
||||
HUnit,
|
||||
QuickCheck == 1.*,
|
||||
enumerable >= 0.0.3
|
||||
enumerable >= 0.0.3,
|
||||
directory >= 1
|
||||
exposed-modules: Web.Restful,
|
||||
Web.Restful.Constants,
|
||||
Web.Restful.Request,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user