5

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?

Jeff Allen
  • 17,277
  • 8
  • 49
  • 70
Mark Heckmann
  • 10,943
  • 4
  • 56
  • 88

1 Answers1

1

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.

Jeff Allen
  • 17,277
  • 8
  • 49
  • 70