-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMain.hs
65 lines (53 loc) · 1.52 KB
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
{-# LANGUAGE OverloadedStrings, LambdaCase, CPP #-}
module Main where
import Web.Scotty
import Data.Maybe (mapMaybe)
import Data.Monoid (mconcat)
import qualified Data.Text.Lazy as LText
import Control.Monad.IO.Class
import Network.WebSockets as WS
import Network.Wai.Handler.WebSockets as WS
import Network.Wai.Handler.Warp as Warp
import Network.Wai.Middleware.RequestLogger as Warp
import Network.Wai.Middleware.Cors
import qualified Data.Aeson as Aeson
import qualified Data.ByteString.Char8 as BS8
import qualified Data.ByteString.Base64 as Base64
import qualified GHC.RTS.Events as GHC
import Network.HTTP.Types.Status (created201, internalServerError500, notFound404)
import EventlogJSON
import FilterEvents
import qualified EndPoint.SourceView as SourceView
import qualified EndPoint.EventLog as EventLog
import qualified EndPoint.FileView as FileView
#ifdef WITH_EXT_STG
import qualified EndPoint.ExtStg as ExtStg
#endif
port = 3000
main :: IO ()
main = do
putStrLn $ "localhost:" ++ show port
app <- httpApp
Warp.run port
$ Warp.logStdoutDev
$ WS.websocketsOr
WS.defaultConnectionOptions
wsApp
app
httpApp = scottyApp $ do
middleware simpleCors
EventLog.endpoints
SourceView.endpoints
FileView.endpoints
#ifdef WITH_EXT_STG
ExtStg.endpoints
#endif
notFound notFoundA
notFoundA :: ActionM ()
notFoundA = do
status notFound404
json ()
wsApp :: WS.ServerApp
wsApp pending_conn = do
conn <- acceptRequest pending_conn
sendTextData conn ("Hello, client!" :: LText.Text)