aboutsummaryrefslogtreecommitdiff
path: root/app/Main.hs
blob: fa816ae3f4dd2c6b0e0d513653adf364162b5639 (plain) (blame)
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
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeOperators #-}
module Main where

import           Data.Proxy                     ( Proxy(..) )
import           Data.Text                      ( Text )
import qualified Data.Text                     as T
import           Network.Wai.Handler.Warp       ( run )
import           Servant                        ( (:>)
                                                , Application
                                                , CaptureAll
                                                , Get
                                                , Handler
                                                , JSON
                                                , Server
                                                , serve
                                                )
import           System.Process                 ( readProcess )

type API = GetPageCompliance

type GetPageCompliance = CaptureAll "url" Text :> Get '[JSON] Text

server :: Server API
server = getPageCompliance

getPageCompliance :: [Text] -> Handler Text
getPageCompliance urlPieces =
  return
    $  "You have requested librejs-compliance info for "
    <> T.intercalate "/" urlPieces

runCompliance :: Text -> IO Text
runCompliance url = T.pack <$> readProcess
  "bin/node"
  ["~/source/librejserver/librejs/utilities/compliance.js", T.unpack url]
  ""

app :: Application
app = serve api server

api :: Proxy API
api = Proxy

main :: IO ()
main = run 5678 app