<commit_before>{-# LANGUAGE OverloadedStrings #-}

module Site (site) where

import qualified Config
import           Data.Aeson
import           Control.Applicative
import           Snap.Core
import           Control.Monad.Trans (liftIO)
import           Server.Test as TestServer

site :: Snap ()
site = method POST (
          route [ ("test", testHandler) ]) <|>
       method GET  (redirect Config.mumukiUrl)

testHandler :: Snap ()
testHandler = do
    setTimeout 8
    Just request <-  decode <$> readRequestBody 102400
    result  <- liftIO . TestServer.process $ request
    writeLBS . encode $ result
<commit_msg>Adding query to routes<commit_after>{-# LANGUAGE OverloadedStrings #-}

module Site (site) where

import qualified Config
import           Data.Aeson
import           Control.Applicative
import           Snap.Core
import           Control.Monad.Trans (liftIO)
import           Server.Test as TestServer
import           Server.Query as QueryServer

site :: Snap ()
site = method POST (
          route [ ("test", testHandler),
                  ("query", queryHandler) ]) <|>
       method GET  (redirect Config.mumukiUrl)


testHandler :: Snap ()
testHandler = handler TestServer.process

queryHandler :: Snap ()
queryHandler = handler QueryServer.process


handler f = do
    setTimeout 8
    Just request <-  decode <$> readRequestBody 102400
    result  <- liftIO . f $ request
    writeLBS . encode $ result
{'fraction_non_alphanumeric': 0.08780487804878048, 'fraction_numerical': 0.00975609756097561, 'mean_word_length': 2.5369458128078817, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4170641', 'n_tokens_mistral': 420, 'n_tokens_neox': 388, 'n_words': 124}