Skip to content

Instantly share code, notes, and snippets.

@dramforever
Created July 5, 2017 08:06
Show Gist options
  • Save dramforever/25f4cdd73c93f7a1834c1ece9ddbfd32 to your computer and use it in GitHub Desktop.
Save dramforever/25f4cdd73c93f7a1834c1ece9ddbfd32 to your computer and use it in GitHub Desktop.
Web app using Transient/Axiom
-- Build instructions: It's complicated
{-# LANGUAGE CPP #-}
module Main where
import Prelude hiding (div, id, span)
import GHCJS.HPlay.View
import Transient.Move
import Control.Monad.IO.Class
main :: IO ()
main = simpleWebApp 8080 fileReader
fileReader :: Cloud ()
fileReader = do
-- Render an input box and a button in the *browser*
fileName <- local . render $
inputString Nothing <* inputSubmit "read" `fire` OnClick
-- Control flow reaches here when button is clicked
teleport -- Go to the server
-- Read the file in the *server*
contents <- local (liftIO (readFile fileName))
teleport -- Back to browser
-- Render the result in the *browser*
local . render . rawHtml $ pre contents
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment