new url for locally served content, which used to be at /p/:port

Bad title, because I don't know what this feature is called (or how to search for a solution). Prior to RStudio Server 1.2, I could preview Jekyll pages that use the relative_url filter by passing the argument --baseurl=/p/4321 to jekyll build in the terminal, and then calling servr::httd('_site', port = 4321 from the R console. This worked, because RStudio Server would proxy the port to my.rstudio.server.com/p/4321/.

Now, RStudio Server uses some alpha-numeric code rather than a port number, so the address looks like my.rstudio.server.com/p/ef22a9ac/. Without knowing the ef22a9ac in advance, I cannot pass the baseurl to jekyll at build time.

Tips on a solution, or where the change is documented, would be greatly appreciated.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

There is a helper function in rstudioapi that translates the port number to the string you mentioned, e.g.,

> rstudioapi::translateLocalUrl('http://127.0.0.1:4321')
[1] "p/9fca296c/"

I hope this helps.

2 Likes

Thanks so much! I think this will help, although I don't immediately see how to get the translation where it needs to go. I use a Makefile to build my GitHub pages site for a local preview before pushing to GitHub. It contains this recipe:

docs/_site: $(SITE) | docs/Gemfile.lock
	pushd docs && bundle exec jekyll build --baseurl=$(BASEURL)p/$(PORT) && popd
	touch docs/_site

Have to get the hash or whatever it is into an environment variable, but from the current RStudio session...

I'll post here when I puzzle it out.

Puzzled it out. Drop this in project's .Rprofile:

setHook("rstudio.sessionInit", function(newSession) {
  if (newSession) {
    Sys.setenv(RSTUDIO_PROXY=rstudioapi::translateLocalUrl('http://127.0.0.1:4321'))
  }
}, action = "append")

and update the Makefile to specify --baseurl=$(BASEURL)$(RSTUDIO_PROXY).

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.