yesod

Parsing a JSON post

人盡茶涼 提交于 2019-12-12 13:35:11
问题 I have the following piece of code: data Friend = Friend { friend_name :: Text , friend_inTwitter :: Bool , friend_twitterName :: Maybe Text } $(deriveJSON (drop 6) ''Friend) This piece of JSON is being posted to a handler, and I'm having a difficult time getting it. I've tried different things, but let me just put one of them here to generate suggestions: postTestR :: Handler RepPlain postTestR = do value <- parseJsonBody_ return $ RepPlain $ friend_name value That doesn't work, and I can

Making Custom Instances of PersistBackend

僤鯓⒐⒋嵵緔 提交于 2019-12-12 13:25:09
问题 I have a monad transformer stack of the form: newtype T m a = T { unT :: StateT State (SqlPersist m) a } deriving (Monad, MonadState State) And want to use the persistent insert and lookup calls, so I need to make a PersistBackend instance for T . However, a phantom type encodes the specific backend into the Key return type - this causes some extra headaches. To solve the phantom type issue, my instance has the form: instance (Monad m, MonadIO m, MonadBaseControl IO m) => PersistBackend T m

Trying to send an email in yesod using hamlet

喜欢而已 提交于 2019-12-12 09:48:29
问题 I am building a survey site in Yesod (0.10) and am getting lost in the types. Here is a simplified version on what I am trying to do. invitation url = do render <- getUrlRender return $ renderHtml [hamlet| <p>Dear foo, please take our <a href=@{ShowSurveyR url}>survey. |] render Another function is going to call this in hopes of getting something that can be passed to simpleMail from Network.Mail.Mime. The above function gives a type error: Handler/Root.hs:404:13: The function `renderHtml' is

Yesod, WebSockets and Persistent

馋奶兔 提交于 2019-12-12 08:38:22
问题 I'm trying to implement a server for a turn based game in Haskell. My choice would be to use Yesod for adminstration and meta-information (like, what games a user participates in and such). I'd like to use web sockets to keep the in-game data overhead small. Looking at the ws-chat example, I'm not sure how to get access to the Handler Monad and with it Persistent. It would be perfect to have some bookkeeping-code for the connections wrapped around a "normal" Handler that itself updates the

Yesod: Using typesafe URLs in AJAX calls

自古美人都是妖i 提交于 2019-12-12 08:29:06
问题 In my Yesod project i have the following route: /api/hide/thread/#Text/#Int ApiHideThreadR GET I want to request it on the client side with javascript: function hideThreadCompletely(threadId, board) { $.getJSON("/api/hide/thread/"+board+"/"+threadId, function(data) { $('#thread-'+threadId).hide(); }); } But i can't use @{ApiHideTHreadR} because Yesod requires it's arguments on compile time. What is the proper solution for this, if i want API URLS to look like api/board/1/1 and not api/board

How to create a custom field which queries the database?

落爺英雄遲暮 提交于 2019-12-12 06:36:00
问题 I’m new to Yesod and would like to create a custom field in which I need to do a query. My model is the following: Article artname Text title Text body Text parent ArticleId Maybe UniqueArt artname deriving Typeable I want to create a "parent field" in which the user enters an artname instead of a numerical id, but it will be the real id which will be stored in the database. I cannot use checkMMap since the invert function works outside of IO. From what I understood of the field processing,

How does one inspect values inside the Handler Monad in ghci?

♀尐吖头ヾ 提交于 2019-12-11 16:52:14
问题 I have a type Handler [Maybe AvailableDay] I would like to inspect the contents of [Maybe AvailableDay] in ghci. How do I do that? 回答1: You cannot simply extract the "contents" of a Handler , as a Handler is really a computation which can depend on the current request, session state and so on. So in order to run it, you'd have to feed it all of that. This would involve using runHandler, followed by unYesodApp, and run on the resulting Iteratee . Technically possible, but incredibly messy to

Change Yesod port number

邮差的信 提交于 2019-12-11 11:53:11
问题 From Deploying Yesod web app, I could copy the executable, static, and config file to run Yesod as a standalone web server. This is the directory structure. ├── config │ ├── client_session_key.aes │ ├── favicon.ico │ ├── keter.yml │ ├── models │ ├── robots.txt │ ├── routes │ ├── settings.yml │ ├── sqlite.yml │ └── test-settings.yml ├── my-project ├── my-project.sqlite3 └── static I tried to use different port by changing config/settings.yml port: "_env:PORT:3002" approot: "_env:APPROOT:http:/

How get the user ID from the Session at (Yesod / Haskell Project

二次信任 提交于 2019-12-11 08:17:27
问题 guys i got a little projet and i need to extrat de ID of the user from the Session. I can't put it in a Text/Int because it says that the Session carry an Key (Sql Key i think) how can i converte it to Int to use in other methods from my project I Tried to do it to recover the ID from session getInicioR :: Handler Html getInicioR = do uid <- lookupSession "_ID" user <- runDB $ get404 uid Shows the follow error message: Couldn't match expected type ‘Key t0’ with actual type ‘Maybe Text’ In the

How to locally run a Yesod web app via Nginx?

拈花ヽ惹草 提交于 2019-12-11 05:49:52
问题 On the Yesod site I have the following (excerpt): staticFiles "assets/" newtype App = App { appStatic :: Static } instance Yesod App where approot = ApprootStatic "http://localhost:9000/yello" main :: IO () main = do appStatic <- static "assets" warp 9000 $ App appStatic So, I'm declaring that my little web application will be hosted at the prefix yello . Now, I want to run this on Nginx ... but don't get the configuration right :( I have the following nginx.conf : daemon off; events { worker