# NOT RUN {
library(beakr)
# Create a .txt file in temp directory
hostDir <- tempdir()
file <- paste0(hostDir, "/my_file.txt")
cat("I am a text file.", file = file)
# Create an new beakr instance
beakr <- newBeakr()
# beakr pipeline
beakr %>%
# Respond to GET requests at the "/hi" route
httpGET(path = "/hi", function(req, res, err) {
print("Hello, World!")
}) %>%
# Respond to GET requests at the "/bye" route
httpGET(path = "/bye", function(req, res, err) {
print("Farewell, my friends.")
}) %>%
# Host the directory of static files
serveStaticFiles("/test", hostDir, verbose = TRUE) %>%
# Start the server on port 25118
listen(host = "127.0.0.1", port = 25118, daemon = TRUE)
# ------------------------------------------------------------
# POINT YOUR BROWSER AT:
# * http://127.0.0.1:25118/test/my_file.txt
#
# THEN, STOP THE SERVER WITH stopServer(beakr)
# ------------------------------------------------------------
# Stop the beakr instance server
stopServer(beakr)
# }
Run the code above in your browser using DataLab