Move to upstream purescript-node-http. (#59)

Move to upstream `purescript-node-http`
This commit is contained in:
Connor Prussin 2017-08-01 21:43:14 -07:00 committed by Connor Prussin
parent 500970b003
commit 61a66c324a
2 changed files with 11 additions and 7 deletions

View File

@ -18,9 +18,9 @@
], ],
"dependencies": { "dependencies": {
"purescript-prelude": "^3.0.0", "purescript-prelude": "^3.0.0",
"purescript-node-http": "cprussin/purescript-node-http#dd87dbaec43ffc5312b78b10316023dc7b78a06d",
"purescript-aff": "^3.1.0", "purescript-aff": "^3.1.0",
"purescript-node-fs": "^4.0.0" "purescript-node-fs": "^4.0.0",
"purescript-node-http": "^4.1.0"
}, },
"devDependencies": { "devDependencies": {
"purescript-psci-support": "^3.0.0", "purescript-psci-support": "^3.0.0",

View File

@ -13,6 +13,7 @@ import Data.Options ((:=))
import Node.Encoding as Encoding import Node.Encoding as Encoding
import Node.FS.Sync as FSSync import Node.FS.Sync as FSSync
import Node.HTTP as HTTP import Node.HTTP as HTTP
import Node.HTTP.Secure as HTTPS
import HTTPure.HTTPureM as HTTPureM import HTTPure.HTTPureM as HTTPureM
import HTTPure.Request as Request import HTTPure.Request as Request
@ -60,11 +61,14 @@ bootHTTPS :: forall e.
ServerM e -> ServerM e ->
ServerM e ServerM e
bootHTTPS options cert key router onStarted = do bootHTTPS options cert key router onStarted = do
certText <- FSSync.readTextFile Encoding.UTF8 cert cert' <- FSSync.readTextFile Encoding.UTF8 cert
keyText <- FSSync.readTextFile Encoding.UTF8 key key' <- FSSync.readTextFile Encoding.UTF8 key
let sslOptions = HTTP.key := keyText <> HTTP.cert := certText server <- HTTPS.createServer (sslOpts key' cert') (handleRequest router)
HTTP.createServerS sslOptions (handleRequest router) >>= \server -> HTTP.listen server options onStarted
HTTP.listen server options onStarted where
sslOpts key' cert' =
HTTPS.key := HTTPS.keyString key' <>
HTTPS.cert := HTTPS.certString cert'
-- | Given a port number, return a HTTP.ListenOptions Record. -- | Given a port number, return a HTTP.ListenOptions Record.
listenOptions :: Int -> HTTP.ListenOptions listenOptions :: Int -> HTTP.ListenOptions