Permalink
Browse files

404 when a fay file doesn't exist

  • Loading branch information...
1 parent 0ae1a1f commit 5ee109681195fba13e4676af74eaa03d394be57b @bergmark bergmark committed Aug 11, 2012
Showing with 8 additions and 8 deletions.
  1. +1 −2 TODO
  2. +7 −6 src/Snap/Snaplet/Fay.hs
View
3 TODO
@@ -1,10 +1,9 @@
-* Typecheck with GHC (prefereably let Fay do it)
+* Typecheck with GHC (preferably let Fay do it)
* Test nested paths /fay-js/foo/bar.js
* Fay splice <script type="text/fay">
* Print errors in HTTP response and in console
* See built-in splices https://github.com/snapframework/heist/tree/master/src/Text/Templating/Heist/Splices
* Check out heist posts on http://softwaresimply.blogspot.com
-* 404 when a fay file doesn't exist
* Document configuration
* Why does Paths_snaplet_fay produce a warning?
* TODO has to recompile if dependencies (imports) changed, should perhaps skip compileAll mode?
View
@@ -9,7 +9,7 @@ module Snap.Snaplet.Fay (
, fayServe
) where
-
+import Control.Applicative
import Control.Monad
import Control.Monad.Reader
import Control.Monad.State.Class
@@ -83,8 +83,7 @@ initFay = makeSnaplet "fay" description datadir $ do
toDestDir :: FilePath -> FilePath
toDestDir = (</> "js")
--- | Serves the compiled Fay scripts
-
+-- | Serves the compiled Fay scripts using the chosen compile method.
fayServe :: Handler b Fay ()
fayServe = do
cfg <- get
@@ -93,12 +92,14 @@ fayServe = do
compileWithMethod :: CompileMethod -> Handler b Fay ()
compileWithMethod CompileOnDemand = do
cfg <- get
- req <- getRequest
- let uri = srcDir cfg </> (toHsName . filename . BS.unpack . rqURI) req
+ uri <- (srcDir cfg </>) . toHsName . filename . BS.unpack . rqURI <$> getRequest
res <- liftIO (compileFile cfg uri)
case res of
Just s -> writeLBS $ fromString s
- Nothing -> return ()
+ Nothing -> do
+ modifyResponse $ setResponseStatus 404 "Not Found"
+ writeBS "File not found."
+ finishWith =<< getResponse
compileWithMethod CompileAll = do
cfg <- get

0 comments on commit 5ee1096

Please sign in to comment.