Skip to content

Commit

Permalink
cmd/server: bind HTTP server with TLS if HTTPS_* variables are defined
Browse files Browse the repository at this point in the history
Fixes: #54
  • Loading branch information
adamdecaf committed Jul 26, 2019
1 parent c004116 commit f5d00e9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ $ go doc github.com/moov-io/wire fedWireMessage

| Environmental Variable | Description | Default |
|-----|-----|-----|
| `HTTPS_CERT_FILE` | Filepath containing a certificate (or intermediate chain) to be served by the HTTP server. Requires all traffic be over secure HTTP. | Empty |
| `HTTPS_KEY_FILE` | Filepath of a private key matching the leaf certificate from `HTTPS_CERT_FILE`. | Empty |
| `WIRE_FILE_TTL` | Time to live (TTL) for `*wire.File` objects stored in the in-memory repository. | 0 = No TTL / Never delete files (Example: `240m`) |

Note: By design Wire **does not persist** (save) any data about the files, batches or entry details created. The only storage occurs in memory of the process and upon restart Wire will have no files, batches, or data saved. Also, no in memory encryption of the data is performed.
Expand Down
15 changes: 11 additions & 4 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,17 @@ func main() {

// Start business logic HTTP server
go func() {
logger.Log("transport", "HTTP", "addr", *httpAddr)
errs <- serve.ListenAndServe()
// TODO(adam): support TLS
// func (srv *Server) ListenAndServeTLS(certFile, keyFile string) error
if certFile, keyFile := os.Getenv("HTTPS_CERT_FILE"), os.Getenv("HTTPS_KEY_FILE"); certFile != "" && keyFile != "" {
logger.Log("startup", fmt.Sprintf("binding to %s for secure HTTP server", *httpAddr))
if err := serve.ListenAndServeTLS(certFile, keyFile); err != nil {
logger.Log("exit", err)
}
} else {
logger.Log("startup", fmt.Sprintf("binding to %s for secure HTTP server", *httpAddr))
if err := serve.ListenAndServe(); err != nil {
logger.Log("exit", err)
}
}
}()

// Block/Wait for an error
Expand Down

0 comments on commit f5d00e9

Please sign in to comment.