rstudio / httpuv

HTTP and WebSocket server package for R
Other
224 stars 84 forks source link

Simple server API #379

Closed jcheng5 closed 10 months ago

jcheng5 commented 10 months ago

In Python you can do this from a shell:

python -m http.server 5000

and this will start a simple static web server on 0.0.0.0:5000 that serves up the current directory as static files. We don't have a simple way to do this with httpuv, this is the equivalent invocation:

httpuv::runServer(app = list(staticPaths=list("/"=httpuv::staticPath(getwd()))), host = "0.0.0.0", port = 5000)

It would be great to have a single function for this, with parameters for:

OR, maybe we create a convenience function to create list(staticPaths=list("/"=httpuv::staticPath(getwd()))) and that becomes the default value for the app parameter of runServer and startServer. Like runServer <- function(host, port, app=staticSite("."), ...)

My motivation for this is to help the story of distributing Shinylive/webR HTML/JS/CSS bundles to end users on Windows, where Python may not be installed. Those bundles cannot be run with the file: protocol, it must be http(s). I'd love to be able to tell them "you can start a little local web server with either python -m http.server or R -e 'httpuv::runServer()'".

cc @rpodcast @wch

jcheng5 commented 10 months ago

It would also be really nice if it printed out Listening on <url> so users can just click that. Right now it starts silently.