Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

serving static files with plumber package - files not found (404)

Tags:

r

plumber

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?

like image 826
Mark Heckmann Avatar asked Nov 08 '22 16:11

Mark Heckmann


1 Answers

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.

like image 135
Jeff Allen Avatar answered Nov 15 '22 08:11

Jeff Allen