Skip to content
This repository has been archived by the owner on Nov 28, 2018. It is now read-only.

Commit

Permalink
Some checking, move bdo.js to a data file
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdone committed Sep 4, 2013
1 parent 15e835e commit 53f296e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions bdo.cabal
Expand Up @@ -9,6 +9,7 @@ maintainer: chrisdone@gmail.com
category: Web
build-type: Simple
cabal-version: >=1.8
data-files: bdo.js

executable bdo
main-is: Main.hs
Expand Down
15 changes: 10 additions & 5 deletions src/Main.hs
@@ -1,7 +1,8 @@
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE OverloadedStrings #-}

-- | Main bdo server. Accepts polling requests and such.
-- | Main bdo server. Accepts polling requests and such. Possibly the
-- worst code I've ever written. I want a prize.

module Main where

Expand All @@ -18,6 +19,7 @@ import qualified Data.Text.Lazy.IO as T
import Http
import Network
import Network.URL
import Paths_bdo
import Prelude hiding (catch)
import System.Environment
import System.IO
Expand Down Expand Up @@ -79,9 +81,12 @@ main = do
["update",client,link] -> update client link
["update"] -> updateCurrentClient
["set",client,link] -> do
modifyMVar_ currentClient (const (return (Just (client,link))))
printCurrentClient
_ -> T.putStrLn $ "Unknown command. Commands: clients, update <client> <stylesheet>"
clients <- readMVar clients
case lookup client clients of
Nothing -> T.putStr "No such client"
Just{} -> do modifyMVar_ currentClient (const (return (Just (client,link))))
printCurrentClient
_ -> T.putStrLn $ "Unknown command. Commands: clients, update <client> <stylesheet>, set <client> <stylesheet> (sets the current client/stylesheet), update (no args, uses current client)"


dispatch :: Handle -> MVar [(Text,([Text],Maybe Handle))] -> Text -> URL -> [Text] -> IO ()
Expand Down Expand Up @@ -127,7 +132,7 @@ logLn = T.hPutStrLn stderr

getJs :: Text -> IO Text
getJs host = do
js <- T.readFile "bdo.js"
js <- getDataFileName "bdo.js" >>= T.readFile
return $
T.unlines [js
,"bdo.host = " <> T.pack (show ("http://" <> host <> "/" :: Text)) <> ";"
Expand Down

0 comments on commit 53f296e

Please sign in to comment.