I want to serve a static file with plumber
as described here. The file with the routes etc. is server.R
:
#* @get /files
function()
{
return(dir("files"))
}
#* @static ./files
list()
This should make the files
directory available on the path /public
. Inside files
there is a file index.html
. Running above code:
library(plumber)
r <- plumb("server.R")
r$run()
Calling localhost:8000/files
returns:
["index.html"]
However, calling localhost:8000/public/index.html
gives a 404 error:
{"error":["404 - Resource Not Found"]}
Printing the r
object, the public path appears to be defined:
> r
<plumber>
Public:
addAssets: function (dir, path = "/public", options = list())
...
Any ideas where I go wrong?
Mea culpa... I silently renamed the annotation for static file servers and (apparently) never updated the docs.
I added a working example here: https://github.com/trestletech/plumber/tree/master/inst/examples/05-static , but the new annotation is @assets
, not @static
. I'll update the docs shortly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With