Skip to content

Commit

Permalink
also allow passing a websocket handler to create_server()
Browse files Browse the repository at this point in the history
  • Loading branch information
yihui committed Nov 3, 2022
1 parent 90dacb4 commit f87c6f6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: servr
Type: Package
Title: A Simple HTTP Server to Serve Static Files or Dynamic Documents
Version: 0.24.3
Version: 0.24.4
Authors@R: c(
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
person("Carson", "Sievert", role = "ctb"),
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CHANGES IN servr VERSION 0.25

- Added a function `create_server()` to create a server with a custom request handler.
- Added a function `create_server()` to create a server with a custom HTTP request handler and optionally a WebSocket handler.

- Added a function 'redirect()` to return a redirect response.

Expand Down
6 changes: 4 additions & 2 deletions R/static.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#' Create a server with a custom handler to handle the HTTP request.
#' @param ... Arguments to be passed to \code{\link{server_config}()}.
#' @param handler A function that takes the HTTP request and returns a response.
#' @param ws_open A function to be called back when a WebSocket connection is
#' established (see \code{httpuv::\link{startServer}()}).
#' @export
#' @examplesIf interactive()
#' # always return "Success:" followed by the requested path
Expand All @@ -15,9 +17,9 @@
#' browseURL(paste0(s$url, '/world'))
#'
#' s$stop_server()
create_server = function(..., handler) {
create_server = function(..., handler, ws_open = function(ws) NULL) {
res = server_config(...)
app = list(call = handler)
app = list(call = handler, onWSOpen = ws_open)
res$start_server(app)
invisible(res)
}
Expand Down
5 changes: 4 additions & 1 deletion man/create_server.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f87c6f6

Please sign in to comment.