## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", eval = FALSE)

## -----------------------------------------------------------------------------
# library(shiny)
# library(brochure)

## -----------------------------------------------------------------------------
# log_where <- function(req) {
#   message(Sys.time(), " - ", req$PATH_INFO)
#   req
# }
# 
# brochureApp(
#   page(href = "/", ui = tagList(h1("Home"))),
#   req_handlers = list(log_where)
# )

## -----------------------------------------------------------------------------
# brochureApp(
#   page(href = "/", ui = tagList(h1("Home"))),
#   page(
#     href = "/healthcheck",
#     ui = tagList(),
#     req_handlers = list(
#       ~ shiny::httpResponse(200, content = "OK")
#     )
#   )
# )

## -----------------------------------------------------------------------------
# require_token <- function(req) {
#   token <- req$HTTP_X_TOKEN
#   if (is.null(token) || !identical(token, Sys.getenv("APP_TOKEN"))) {
#     return(shiny::httpResponse(401, content = "Unauthorized"))
#   }
#   req
# }
# 
# brochureApp(
#   page(href = "/", ui = tagList(h1("Home"))),
#   req_handlers = list(require_token)
# )

## -----------------------------------------------------------------------------
# brochureApp(
#   page(href = "/", ui = tagList(h1("Home"))),
#   res_handlers = list(
#     function(res, req) {
#       res$headers$`X-Frame-Options` <- "DENY"
#       res
#     }
#   )
# )

## -----------------------------------------------------------------------------
# subscribe <- function(req) {
#   fields <- shiny::parseQueryString(
#     rawToChar(req$rook.input$read())
#   )
#   message("new subscriber: ", fields$email)
#   req
# }
# 
# brochureApp(
#   page(
#     href = "/",
#     ui = tagList(
#       tags$form(
#         action = "/subscribe",
#         method = "post",
#         tags$input(type = "email", name = "email"),
#         tags$input(type = "submit", value = "Subscribe")
#       )
#     )
#   ),
#   page(
#     href = "/subscribe",
#     method = "POST",
#     ui = tagList(h1("Thanks")),
#     req_handlers = list(subscribe)
#   )
# )

