Comments (2)
@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.
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)
- integration with OpenAPI HOT 5
- Add "base_url" option, to "up()" to lop off referrer route path sent in from proxy servers (e.g. nginx)? HOT 7
- Loading Genie affects conversion of JSON3.Dict into Dict HOT 2
- Passing variables to `html` renderer yields key not found error HOT 4
- hot reload not possible once application hit the error, it require new bootstrap even in GENIE_ENV=dev HOT 4
- Genie.Logger.initialize_logging causes slow Arrow writes HOT 5
- Error reporting dumps sensitive information HOT 3
- Setting EARLYBIND "true" in Dockerfile causes port in use error HOT 3
- index-base transation missing. HOT 1
- Syntax error in first dashboard tutorial HOT 2
- [Bug] can't access own structure's properties in the reactive way HOT 11
- Typos in "your first dashboard" page in the website HOT 3
- Bug: Genie.Renderer.Html.html changes encoding when used with filepath HOT 2
- GC corrution in Genie[Session] HOT 1
- Applications compiled with Genie 5.23.x crashes (expected package `TimeZones [f269a46b]` to exist in the manifest) HOT 1
- Layout example does not work HOT 1
- Issues with the controller example from the docs HOT 4
- Multiple app modules no longer works HOT 6
- How to make the new Genie work behind nginx HOT 12
- Genie gives rise to a large number of GenieSession files via GenieSessionFileSession with enormous footprint >300GB HOT 26
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from genie.jl.