Add documentation for a shutdown hook (#174)
This commit is contained in:
parent
2f815ce336
commit
8f1730c00b
@ -64,3 +64,31 @@ main =
|
|||||||
HTTPure.serveSecure' customSSLOptions customOptions router $
|
HTTPure.serveSecure' customSSLOptions customOptions router $
|
||||||
Console.log "Server up"
|
Console.log "Server up"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Shutdown hook
|
||||||
|
|
||||||
|
To gracefully shut down a server you can add a shutdown hook. For this you will need to add the following dependencies:
|
||||||
|
```
|
||||||
|
posix-types
|
||||||
|
node-process
|
||||||
|
```
|
||||||
|
|
||||||
|
Then take the closing handler returned by `serve` and create a `SIGINT` and `SIGTERM` hook:
|
||||||
|
|
||||||
|
```purescript
|
||||||
|
import Prelude
|
||||||
|
|
||||||
|
import Data.Posix.Signal (Signal(..))
|
||||||
|
import Effect (Effect)
|
||||||
|
import Effect.Console as Console
|
||||||
|
import HTTPure as HTTPure
|
||||||
|
import Node.Process (onSignal)
|
||||||
|
|
||||||
|
main :: Effect Unit
|
||||||
|
main = do
|
||||||
|
closingHandler <- HTTPure.serve 8080 (const $ HTTPure.ok "hello world!") do
|
||||||
|
Console.log $ "Server now up on port 8080"
|
||||||
|
|
||||||
|
onSignal SIGINT $ closingHandler $ Console.log "Received SIGINT, stopping service now."
|
||||||
|
onSignal SIGTERM $ closingHandler $ Console.log "Received SIGTERM, stopping service now."
|
||||||
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user