Giter Club home page Giter Club logo

Comments (2)

essenciary avatar essenciary commented on June 1, 2024 1

@rssdev10 I don't fully understand the use case so maybe you can provide an example of what you're trying to serve. I can think of a few approaches but without understanding exactly what you want to achieve, I don't know what's best.

But before we dive into that, it's worth noting that the approach you propose would not be recommended for many files, as you're registering a route for each static file.

Now for the options:

1/ in the upcoming Genie 6 (currently in the v6 branch) I've added support for star subroutes(?! lacking a better name) - so you could register a route like

# Genie 6 code
route("/components/*") do params 
  serve_static_file(joinpath(your_components_folder, params["_"]))
end

The route part corresponding to the * is added to params["_"]. (Maybe a better key than _ would be good).
Note to myself to test and document the feature.
This can also be backported to v5, it's just a few lines of code.

2/ As is, Genie already first checks if the path of a request is a static file. So if you put them inside the public folder, that should already work. If you don't want to put them into the public folder (why not?), we could add support for multiple "public" folders. So we could add multiple such folder and Genie could check in all of them (which would still be much more efficient that registering a route for each file).

3/ You could add a router hook - this would cause Genie to automatically invoke the function you define before running the route matching code. In your hook you could process the request and return the static file response if it's a match (this might also work better in v6 due to recent changes).

What do you think? What makes more sense for your use case? I can take a closer look.

from genie.jl.

rssdev10 avatar rssdev10 commented on June 1, 2024

Thanks, the case with route("/components/*") do params ... end looks good. The only point I want to add here - the value of params["_"] must be sanitized by default (at least to remove a relative path). See an example https://guides.rubyonrails.org/security.html#file-uploads. Regarding the name, may be it would be good to copy RoR approach...

The case with the custom location of the public path happened when we used Genie by components. In this case, we don't have a typical set of directories in the project. And our static files are in different locations. The case with multiple static public paths can also be useful if we have some different groups of files.

Other case with a custom static path - use the webpack or something like that to implement the frontend.

As for the backport to Genie 5, I can check it out next week.

from genie.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.