Created
July 5, 2017 08:06
-
-
Save dramforever/25f4cdd73c93f7a1834c1ece9ddbfd32 to your computer and use it in GitHub Desktop.
Web app using Transient/Axiom
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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