1# Serving web applications over HTTPS
3This short recipe shows how one can serve a servant application
4over HTTPS, by simply using `warp-tls` instead of `warp` to provide
5us a `run` function for running the `Application` that we get by
8As usual, we start by clearing our throat of a few language extensions
12{-# LANGUAGE DataKinds #-}
13{-# LANGUAGE TypeOperators #-}
15import Network.Wai.Handler.Warp
16import Network.Wai.Handler.WarpTLS
20No need to work with a complicated API here, let's
21make it as simple as it gets:
24type API = Get '[JSON] Int
36It's now time to actually run the `Application`.
37The [`warp-tls`](https://hackage.haskell.org/package/warp-tls/docs/Network-Wai-Handler-WarpTLS.html)
38package provides two functions for running an `Application`, called
39[`runTLS`](https://hackage.haskell.org/package/warp-tls/docs/Network-Wai-Handler-WarpTLS.html#v:runTLS)
40and [`runTLSSocket`](https://hackage.haskell.org/package/warp-tls/docs/Network-Wai-Handler-WarpTLS.html#v:runTLSSocket).
41We will be using the first one.
43It takes two arguments,
44[the TLS settings](https://hackage.haskell.org/package/warp-tls/docs/Network-Wai-Handler-WarpTLS.html#t:TLSSettings)
45(certificates, keys, ciphers, etc)
46and [the warp settings](https://hackage.haskell.org/package/warp/docs/Network-Wai-Handler-Warp-Internal.html#t:Settings)
49We will be using very simple settings for this example but you are of
50course invited to read the documentation for those types to find out
51about all the knobs that you can play with.
55main = runTLS tlsOpts warpOpts app
57 where tlsOpts = tlsSettings "cert.pem" "secret-key.pem"
58 warpOpts = setPort 8080 defaultSettings
61This program is available as a cabal project
62[here](https://github.com/haskell-servant/servant/tree/master/doc/cookbook/https).
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list