on master help sign in
Embedding static files for wai-websockets-example
commit8f0d068ab3054aeb28cd8536d5be1ae12654cbec authorMichael Snoyman <michael@snoyman.com> dateWed 5 Oct 2011, 23:21 (15 years ago) parent8338040
5 files changed+6−2
wai-websockets/server.lhs+4−1 wai-websockets/client.html → wai-websockets/static/client.html wai-websockets/client.js → wai-websockets/static/client.js wai-websockets/screen.css → wai-websockets/static/screen.css wai-websockets/wai-websockets.cabal+2−1
wai-websockets/server.lhs+4−1
@@ -2,6 +2,7 @@ This is the Haskell implementation of the example for the WebSockets library. We
22implement a simple multi-user chat program.
33
44> {-# LANGUAGE OverloadedStrings #-}
5+> {-# LANGUAGE TemplateHaskell #-}
56> import Data.Char (isPunctuation, isSpace)
67> import Data.Monoid (mappend)
78> import Data.Text (Text)
@@ -15,6 +16,7 @@ implement a simple multi-user chat program.
1516> import qualified Network.Wai.Handler.Warp as Warp
1617> import qualified Network.Wai.Handler.WebSockets as WaiWS
1718> import qualified Network.Wai.Application.Static as Static
19+> import Data.FileEmbed (embedDir)
1820
1921We represent a client by his username and a 'WS.Sender'. We can use this sender
2022to asynchronously send 'Text' to the client later.
@@ -66,6 +68,7 @@ actual server. For this purpose, we use the simple server provided by
6668
6769> main :: IO ()
6870> main = do
71+> putStrLn "http://localhost:9160/client.html"
6972> state <- newMVar newServerState
7073> Warp.runSettings Warp.defaultSettings
7174> { Warp.settingsPort = 9160
@@ -73,7 +76,7 @@ actual server. For this purpose, we use the simple server provided by
7376> } staticApp
7477
7578> staticApp = Static.staticApp Static.defaultFileServerSettings
76−> { Static.ssFolder = Static.fileSystemLookup $ Static.toFilePath "."
79+> { Static.ssFolder = Static.embeddedLookup $ Static.toEmbedded $(embedDir "static")
7780> }
7881
7982> webSocketsApp state = do
wai-websockets/client.html → wai-websockets/static/client.htmlrenamed

The content is the same.

wai-websockets/client.js → wai-websockets/static/client.jsrenamed

The content is the same.

wai-websockets/screen.css → wai-websockets/static/screen.cssrenamed

The content is the same.

wai-websockets/wai-websockets.cabal+2−1
@@ -41,7 +41,8 @@ Executable wai-websockets-example
4141 enumerator,
4242 transformers,
4343 network,
44− text
44+ text,
45+ file-embed
4546
4647 ghc-options: -Wall -O2 -threaded
4748 main-is: server.lhs