<commit_before>module Node.Express.App
    ( AppM()
    , App()
    , listen, use, useExternal, useAt, useOnParam, useOnError
    , getProp, setProp
    , http, get, post, put, delete, all
    ) where

import Data.Foreign
import Data.Function
import Data.Maybe
import Control.Monad.Eff
import Control.Monad.Eff.Class

import Node.Express.Types
import Node.Express.Internal.App
import Node.Express.Handler


--| Monad responsible for application related operations (initial setup mostly).
data AppM a = AppM (Application -> ExpressM a)
type App = AppM Unit

instance functorAppM :: Functor AppM where
    (<$>) f (AppM h) = AppM \app -> liftM1 f $ h app

instance applyAppM :: Apply AppM where
    (<*>) (AppM f) (AppM h) = AppM \app -> do
        res <- h app
        trans <- f app
        return $ trans res

instance applicativeAppM :: Applicative AppM where
    pure x = AppM \_ -> return x

instance bindAppM :: Bind AppM where
    (>>=) (AppM h) f = AppM \app -> do
        res <- h app
        case f res of
             AppM g -> g app

instance monadAppM :: Monad AppM

instance monadEffAppM :: MonadEff AppM where
    liftEff act = AppM \_ -> liftEff act


--| Run application on specified port and execute callback after launch.
listen :: forall e. App -> Port -> (Event -> Eff e Unit) -> ExpressM Unit
listen (AppM act) port cb = do
    app <- intlMkApplication
    act app
    intlAppListen app port cb

--| Use specified middleware handler.
use :: Handler -> App
use middleware = AppM \app ->
    intlAppUse app $ withHandler middleware

--| Use any function as middleware.
--  Introduced to ease usage of a bunch of external
--  middleware written for express.js.
--  See http://expressjs.com/4x/api.html#middleware
useExternal :: Fn3 Request Response (ExpressM Unit) (ExpressM Unit) -> App
useExternal fn = AppM \app ->
    intlAppUseExternal app fn

--| Use specified middleware only on requests matching path.
useAt :: Path -> Handler -> App<commit_msg>! Fix for situations where call to require('express') has been optimized out<commit_after>module Node.Express.App
    ( AppM()
    , App()
    , listen, use, useExternal, useAt, useOnParam, useOnError
    , getProp, setProp
    , http, get, post, put, delete, all
    ) where

import Data.Foreign
import Data.Function
import Data.Maybe
import Control.Monad.Eff
import Control.Monad.Eff.Class

import Node.Express.Types
import Node.Express.Internal.App
import Node.Express.Handler


--| Monad responsible for application related operations (initial setup mostly).
data AppM a = AppM (Application -> ExpressM a)
type App = AppM Unit

instance functorAppM :: Functor AppM where
    (<$>) f (AppM h) = AppM \app -> liftM1 f $ h app

instance applyAppM :: Apply AppM where
    (<*>) (AppM f) (AppM h) = AppM \app -> do
        res <- h app
        trans <- f app
        return $ trans res

instance applicativeAppM :: Applicative AppM where
    pure x = AppM \_ -> return x

instance bindAppM :: Bind AppM where
    (>>=) (AppM h) f = AppM \app -> do
        res <- h app
        case f res of
             AppM g -> g app

instance monadAppM :: Monad AppM

instance monadEffAppM :: MonadEff AppM where
    liftEff act = AppM \_ -> liftEff act


--| Run application on specified port and execute callback after launch.
listen :: forall e. App -> Port -> (Event -> Eff e Unit) -> ExpressM Unit
listen (AppM act) port cb = do
    pure express -- DO NOT DELETE THIS LINE
    -- Otherwise call to 'require(express)' may be optimized out
    app <- intlMkApplication
    act app
    intlAppListen app port cb

--| Use specified middleware handler.
use :: Handler -> App
use middleware = AppM \app ->
    intlAppUse app $ withHandler middleware

--| Use any function as middleware.
--  Introduced to ease usage of a bunch of external
--  middleware written for express.js.
--  See http://expressjs.com/4x/api.html#middleware
useExternal :: Fn3 Request Response (ExpressM Unit) (ExpressM Unit) -> App
useExternal fn = AppM \app ->
    intlAppUseExternal app fn

--| Use specified middleware only on requests matching path.
useAt :: Path -> Handler -> App
{'fraction_non_alphanumeric': 0.09795819154107924, 'fraction_numerical': 0.0014584346135148275, 'mean_word_length': 2.9078822412155745, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 45, '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': '5686906', 'n_tokens_mistral': 1276, 'n_tokens_neox': 1244, 'n_words': 493}