Skip to content

Only listen on 127.0.0.1 #177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion server/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import qualified Data.Aeson as A
import Data.Aeson ((.=))
import Data.Bifunctor (first, second)
import qualified Data.ByteString.Lazy as BL
import Data.Default (def)
import Data.Function (on)
import Data.List (foldl', nubBy)
import qualified Data.List.NonEmpty as NE
Expand All @@ -41,6 +42,7 @@ import qualified Language.PureScript.CoreFn as CF
import qualified Language.PureScript.Errors.JSON as P
import qualified Language.PureScript.Interactive as I
import qualified Language.PureScript.TypeChecker.TypeSearch as TS
import qualified Network.Wai.Handler.Warp as Warp
import System.Environment (getArgs)
import System.Exit (exitFailure)
import System.FilePath ((</>))
Expand Down Expand Up @@ -89,7 +91,7 @@ server externs initNamesEnv initEnv port = do
Right _ ->
(return . Left . OtherError) "The name of the main module should be Main."

scotty port $ do
scottyOpts (getOpts port) $ do
get "/" $
Scotty.text "POST api.purescript.org/compile"
post "/compile" $ do
Expand Down Expand Up @@ -120,6 +122,14 @@ server externs initNamesEnv initEnv port = do
]
]

getOpts :: Int -> Scotty.Options
getOpts port = def
{ settings =
Warp.setHost "127.0.0.1"
$ Warp.setPort port
$ Warp.defaultSettings
}

lookupAllConstructors :: P.Environment -> P.SourceType -> [P.SourceType]
lookupAllConstructors env = P.everywhereOnTypesM $ \case
P.TypeConstructor ann (P.Qualified Nothing tyCon) -> P.TypeConstructor ann <$> lookupConstructor env tyCon
Expand Down
4 changes: 3 additions & 1 deletion trypurescript.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ executable trypurescript
build-depends: base ==4.*,
aeson -any,
bytestring >=0.10.0.2 && <0.11,
data-default -any,
directory -any,
filepath -any,
Glob -any,
Expand All @@ -27,7 +28,8 @@ executable trypurescript
mtl ==2.2.2,
parsec,
text -any,
time -any
time -any,
warp -any
hs-source-dirs: server
main-is: Main.hs
buildable: True
Expand Down