sinatra / sinatra/sinatra

Add the ability to dynamically re-assign the static "folder" (although I realised, I can use symlink as workaround)

Open
#2,105 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
12.5k
Forks
2.1k
PR merge metrics
No merged PRs in 30d

Description

We can set the public "folder" via set such as:

set :public_folder, __dir__ + '/static'

I would like to change the public folder, specifically to serve some video files that
are accessed only via /video/.

(I suppose I could use symlinks to the public "folder" but I find it more elegant to just
re-assign the public "folder" directve.)

Right now I am not sure how this can be done. I thought about doing so within the
route, but set() does not work there, as it only works on the toplevel. Could this
functionality be added, and also documented in the official sinatra tutorial?

I'd like to use another public directory depending on which sub-functionality
is to be used, e. g. one directory for when working with .pdf files, another one
for when working with multimedia files and so forth.

Edit: Hmm, symlinks work, so I have a workaround, even though it is not very
elegant. It works on Linux, though, not sure if that would work on windows.
So I'd still have that use case on windows. Another alternative is to probably
just set the public directory to the root of the filesystem or where I keep
those video files (e. g. /home/x/video/ also on windows, or some other
subdirectory). Not elegant but I guess this here is semi-solved.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing Sinatra's public_folder configuration and the static-file handling used by routes. Define how reassignment should work during request handling, cover the behavior with tests, and update the official tutorial if the feature is accepted.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
backend, web-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.