Skip to content

Commit 47ec7c0

Browse files
authored
Only listen on 127.0.0.1 (#177)
Resolves #161
1 parent 9f509bd commit 47ec7c0

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

server/Main.hs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import qualified Data.Aeson as A
2121
import Data.Aeson ((.=))
2222
import Data.Bifunctor (first, second)
2323
import qualified Data.ByteString.Lazy as BL
24+
import Data.Default (def)
2425
import Data.Function (on)
2526
import Data.List (foldl', nubBy)
2627
import qualified Data.List.NonEmpty as NE
@@ -41,6 +42,7 @@ import qualified Language.PureScript.CoreFn as CF
4142
import qualified Language.PureScript.Errors.JSON as P
4243
import qualified Language.PureScript.Interactive as I
4344
import qualified Language.PureScript.TypeChecker.TypeSearch as TS
45+
import qualified Network.Wai.Handler.Warp as Warp
4446
import System.Environment (getArgs)
4547
import System.Exit (exitFailure)
4648
import System.FilePath ((</>))
@@ -89,7 +91,7 @@ server externs initNamesEnv initEnv port = do
8991
Right _ ->
9092
(return . Left . OtherError) "The name of the main module should be Main."
9193

92-
scotty port $ do
94+
scottyOpts (getOpts port) $ do
9395
get "/" $
9496
Scotty.text "POST api.purescript.org/compile"
9597
post "/compile" $ do
@@ -120,6 +122,14 @@ server externs initNamesEnv initEnv port = do
120122
]
121123
]
122124

125+
getOpts :: Int -> Scotty.Options
126+
getOpts port = def
127+
{ settings =
128+
Warp.setHost "127.0.0.1"
129+
$ Warp.setPort port
130+
$ Warp.defaultSettings
131+
}
132+
123133
lookupAllConstructors :: P.Environment -> P.SourceType -> [P.SourceType]
124134
lookupAllConstructors env = P.everywhereOnTypesM $ \case
125135
P.TypeConstructor ann (P.Qualified Nothing tyCon) -> P.TypeConstructor ann <$> lookupConstructor env tyCon

trypurescript.cabal

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ executable trypurescript
1616
build-depends: base ==4.*,
1717
aeson -any,
1818
bytestring >=0.10.0.2 && <0.11,
19+
data-default -any,
1920
directory -any,
2021
filepath -any,
2122
Glob -any,
@@ -27,7 +28,8 @@ executable trypurescript
2728
mtl ==2.2.2,
2829
parsec,
2930
text -any,
30-
time -any
31+
time -any,
32+
warp -any
3133
hs-source-dirs: server
3234
main-is: Main.hs
3335
buildable: True

0 commit comments

Comments
 (0)