on master help sign in
Find index.html in every directory.
4561887Jasper Van der Jeugt
src/Network/Hakyll/SimpleServer.hs+4−3
@@ -8,7 +8,7 @@ import Network
8import Control.Monad (forever, mapM_)
8import Control.Monad (forever, mapM_)
9import Control.Monad.Reader (ReaderT, runReaderT, ask, liftIO)
9import Control.Monad.Reader (ReaderT, runReaderT, ask, liftIO)
10import System.IO (Handle, hClose, hGetLine, hPutStr)
10import System.IO (Handle, hClose, hGetLine, hPutStr)
11−import System.Directory (doesFileExist)
11+import System.Directory (doesFileExist, doesDirectoryExist)
12import Control.Concurrent (forkIO)
12import Control.Concurrent (forkIO)
13import System.FilePath (takeExtension)
13import System.FilePath (takeExtension)
14import qualified Data.ByteString.Char8 as B
14import qualified Data.ByteString.Char8 as B
@@ -92,8 +92,9 @@ createGetResponse request = do
92 -- Construct the complete fileName of the requested resource.
92 -- Construct the complete fileName of the requested resource.
93 config <- ask
93 config <- ask
94 let uri = B.unpack (requestURI request)
94 let uri = B.unpack (requestURI request)
95+ isDirectory <- liftIO $ doesDirectoryExist $ documentRoot config ++ uri
95− fileName = (documentRoot config) ++ if uri == "/" then "/index.html"
96+ let fileName = (documentRoot config) ++ if isDirectory then uri ++ "/index.html"
96− else B.unpack (requestURI request)
97+ else uri
97
98
98 -- Send back the page if found.
99 -- Send back the page if found.
99 exists <- liftIO $ doesFileExist fileName
100 exists <- liftIO $ doesFileExist fileName