aboutsummaryrefslogtreecommitdiff
path: root/app/Main.hs
diff options
context:
space:
mode:
Diffstat (limited to 'app/Main.hs')
-rw-r--r--app/Main.hs45
1 files changed, 40 insertions, 5 deletions
diff --git a/app/Main.hs b/app/Main.hs
index fa816ae..8dd0f47 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -1,3 +1,23 @@
+{-
+Copyright (C) 2022 Yuchen Pei.
+
+This file is part of librejserver.
+
+librejserver is free software: you can redistribute it and/or modify it under
+the terms of the GNU Affero General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+librejserver is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General
+Public License for more details.
+
+You should have received a copy of the GNU Affero General Public
+License along with librejserver. If not, see <https://www.gnu.org/licenses/>.
+
+-}
+
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeOperators #-}
@@ -7,6 +27,7 @@ import Data.Proxy ( Proxy(..) )
import Data.Text ( Text )
import qualified Data.Text as T
import Network.Wai.Handler.Warp ( run )
+import Paths_librejserver
import Servant ( (:>)
, Application
, CaptureAll
@@ -16,7 +37,13 @@ import Servant ( (:>)
, Server
, serve
)
-import System.Process ( readProcess )
+import System.IO ( hGetContents )
+import System.Process ( CreateProcess(..)
+ , createProcess
+ , proc
+ , readCreateProcess
+ , readProcess
+ )
type API = GetPageCompliance
@@ -25,17 +52,25 @@ type GetPageCompliance = CaptureAll "url" Text :> Get '[JSON] Text
server :: Server API
server = getPageCompliance
+-- TODO: use runCompliance once that function is fixed.
getPageCompliance :: [Text] -> Handler Text
getPageCompliance urlPieces =
return
$ "You have requested librejs-compliance info for "
<> T.intercalate "/" urlPieces
+-- FIXME: not working: selenium webdriver says
+-- Error: Server terminated early with status 127
runCompliance :: Text -> IO Text
-runCompliance url = T.pack <$> readProcess
- "bin/node"
- ["~/source/librejserver/librejs/utilities/compliance.js", T.unpack url]
- ""
+runCompliance url = do
+ dataDir <- getDataDir
+ T.pack
+ <$> readCreateProcess
+ (proc "node" ["./utilities/compliance.js", T.unpack url])
+ { cwd = Just (dataDir ++ "/librejs")
+ , env = Just [("PATH", "$PATH:./node_modules/.bin")]
+ }
+ []
app :: Application
app = serve api server