How can I detect queries created by other queries using Ruby and Puma?

Let me try to explain what I need.

When I include a library like Bootstrap in my HTML page and this page loads, the main library files are also loaded. Most of the time, library files require other files. So I used Bootstrap as an example, let us consider glyphicons-halflings-regular.svg, glyphicons-halflings-regular.ttf, glyphicons-halflings-regular.woffand glyphicons-halflings-regular.woff2all of them are part of Bootstrap.

I am writing Rack middleware to process requests from my application. One of the tasks of this middleware is to modify the queries in accordance with certain conventions. For example, in my application Bootstrap will be on this path

ENV['HOME']/my_app/web/libraries/bootstrap/

and its main CSS file will be

ENV['HOME']/my_app/web/libraries/bootstrap/css/bootstrap.css

And at boot, it will generate new requests for all of the files mentioned above.

I need to determine that another file, say glyphicons-halflings-regular.svg, is required by others, so I can use the Rack middleware to change its location accordingly. How:

Requested file:
    `glyphicons-halflings-regular.svg`
Requested-by:
    http://my_app_domain.com/web/libraries/bootstrap/css/bootstrap.css
Request address:
    http://my_domain_app.com/web/libraries/bootstrap/css/../fonts/glyphicons-halflings-regular.svg

At least I started a thread for every new request. Then I will only need to consider the address of the main file as the base address and add it to each subquery generated by this file.

. ?

EDIT: ( spickermann)

, . , , .

:

ENV['HOME']/my_app/web/libraries/library1/
                                |        |
                                |        |_ a_css_file.css
                                |        |_ a_jpeg_file.jpg
                                |
                                /library2/
                                         |
                                         |_ another_css_file.css
                                         |_ a_jpeg_file.jpg

, a_jpeg_file.jpg. , library1 library2.

, , , a_jpeg_file.jpg a_css_file.css another_css_file.css.

library1 ENV['HOME']/my_app/web/libraries/library1/. library2 ENV['HOME']/my_app/web/libraries/library2/.

, a_jpeg_file.jpg.

, , .

+4
1

, , like my-image.jpg?dir='dir1' . Rails . , , image.jpt?info=HughYF65fFj7t..., , .

+3

Source: https://habr.com/ru/post/1660809/


All Articles