Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
send and delete a file with Yesod
{-# LANGUAGE TemplateHaskell
, QuasiQuotes
, OverloadedStrings
, TypeFamilies
#-}
import Yesod
import Yesod.Handler
import Data.Maybe
import System.IO
import System.Directory
import System.Process
import Text.Printf
import Network.Wai
-- http://github.com/softmechanics/wai/commit/2cb5ea47ca458f4b91a73e01a1dd0a29e84e001e
import Network.Wai.Enumerator (fromTempFile)
type Handler = GHandler SendTempFile SendTempFile
data SendTempFile = SendTempFile
mkYesod "SendTempFile" [$parseRoutes|
/ RootR GET
|]
instance Yesod SendTempFile where approot _ = ""
tempFileChooseRep :: ContentType -> FilePath -> ChooseRep
tempFileChooseRep ct fp = const $ return (ct, ResponseEnumerator $ fromTempFile fp)
sendTempFile :: ContentType -> FilePath -> GHandler sub master a
sendTempFile ct fp = sendResponse $ tempFileChooseRep ct fp
genGraph :: IO FilePath
genGraph = do
(f,h) <- openTempFile "/tmp" "tmp.txt"
hPutStrLn h f
hClose h
return f
getRootR :: Handler ()
getRootR = do
liftIO genGraph >>= sendTempFile typePlain
main = do
basicHandler 3000 SendTempFile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.