yesod

Is there a way to kill all forked threads in a GHCi session without restarting it?

[亡魂溺海] 提交于 2019-12-08 15:24:55
问题 Based on my previous question I'd like to ask if there's any way to kill all user created threads in a GHCi session? The reason for this is that when a function exits in GHCi the threads that it spawned don't terminate automatically, persisting even through code reloads. Restarting GHCi solves this, but since my application takes a while to load, it would be great if there was a possible (even hacky) workaround. 回答1: No, and actually for almost the same reasons as in How can I build a

Yesod handlers, content of POSTed files

给你一囗甜甜゛ 提交于 2019-12-08 11:14:54
问题 while the following code: postImportR = do fi <- lookupFiles "file" fc <- lift $ fileSource (fi !! 0) $$ consume seems to work (at least can I "liftIO $ print fc), splitting it off to a function for iterating doesn't: process :: [FileInfo] -> [String] process [] = [] process (f:r) = do fn <- fileName f fc <- lift $ fileSource f $$ consume ([fn] : (process r)) postImportR = do fi <- lookupFiles "file" process fi or even with a lambda function: files <- L.map (\f -> (fileName f, lift $

What is the IForm equivalent to fileAFormOpt?

无人久伴 提交于 2019-12-08 08:14:36
问题 I want to use runInputPost on an existing form with a file input tag. fileAFormOpt exists for AForms, but how can I do the same with an IForm since there is no fileField type? 回答1: I would recommend using lookupFile for that use case. 来源: https://stackoverflow.com/questions/12811776/what-is-the-iform-equivalent-to-fileaformopt

Where to add 'always running' thread to Yesod applications

江枫思渺然 提交于 2019-12-08 00:31:27
问题 I'm writing a Yesod application, but it also needs to fork several non-web services. (UDP listeners, TCP listening port, etc.) Where is the correct place to splice in a fork, such that this work seamlessly, regardless of whether my app is running in 'yesod devel' or deployed for production. P.S. I really just want to add a pseudo-Main, which will be forked (at service start) by whichever webserver runs the app through WAI. 回答1: You should put it in the makeApplication function in the

How can I post FileInfo to a web service using Yesod and Http-Conduit?

半腔热情 提交于 2019-12-07 10:31:28
问题 I am working with the default Yesod scaffolding project. I have created a page that displays a simple form to upload files. (The form will likely be created on the client using Javascript.) For brevity, the form has a single file input: <form method="post" action=@{UploadR}> <input type="file" name="myfile"> <button type="submit"> My objective is to process the form data and then upload the file to a web service. I have no trouble processing the form, my concern is interacting with the web

Yesod form with multiple buttons

让人想犯罪 __ 提交于 2019-12-07 08:49:33
问题 I have a Yesod form for editing the contents of some static pages which are written using markdown (processed using Pandoc). I want to have two buttons - a 'preview' button which processes the markup and displays the result underneath the form, and a 'submit' button which saves the contents to the database. What is the simplest way to do this with Yesod? All the form examples in the Yesod book have exactly one button. I've looked at the exposed functions / api, but I even if I add more than

Yesod auth: redirecting user to registration page

随声附和 提交于 2019-12-07 07:56:49
问题 I'm playing with scaffolded site and i want to send user to the registration page after he logged in for the first time with OpenID or Google Account. I've came up with this: getAuthId creds = runDB $ do x ← getBy $ UniqueUser $ credsIdent creds case x of Just (Entity uid _) → return $ Just uid Nothing → do return $ Just $ Key (PersistInt64 0) And in HomeR handler i check for UserId value, showing registration form in case of zero. This approach works, but seems hackish. What is the proper

Yesod devel server only listening on ipv6

安稳与你 提交于 2019-12-07 06:36:47
问题 I'm running "cabal install && yesod devel" using yesod 0.9.2.2 but it is only listening using ipv6. Does anyone know how to configure it to listen on ipv4 as well? I'm running it on Windows 7. Thanks 回答1: The symptom you describe have so far been observed on BSD and Debian, but it looks like Windows is also affected. It is a known problem with Yesod, or actually with Wasp, or, to be precise, with the network library. One place to follow up on this issue is this githup issue or the current

Websockets in Yesod?

感情迁移 提交于 2019-12-06 22:14:03
问题 I would like to create a website using Yesod and websockets (html5). Can I use websockets with Yesod webframework? 回答1: Yes, as Thomas M. DuBuisson pointed out in the comments: a WebSocket handler is implemented in WAI which is the interface Yesod is using to communicate with it's backends. I can't comment on how well it works in it's current form, but you can download and try it from Hackage. 来源: https://stackoverflow.com/questions/10963175/websockets-in-yesod

Using Servant with Yesod shakespeare (Hamlet, Julius, Lucius)

旧巷老猫 提交于 2019-12-06 14:56:32
How i can use shakespeare (from yesod) for servant webservices APIs? I try: type TestAPI = "tests" :> Get '[JSON] [Test] :<|> "Test.html" :> Get '[HTML] Html serverTestAPI :: ServerT TestAPI AppM serverTestAPI = tests :<|> test :<|> testHtml tests :: AppM [Test] tests = do return [ Test 1 "Test 1" , Test 2 "Test 2" ] testHtml = [hamlet| $doctype 5 ......... |] But I get error! As @Carsten points out, in this case what you want is shamlet . The key thing is implementing proper instances of the ToMarkup typeclass. I recommend you to read this excellent introduction on Shakespeare templates. A