roadrunner-server / roadrunner-plugins

📦 Home for the roadrunner plugins
MIT License
25 stars 9 forks source link

feat(fileserver): new static files server #130

Closed rustatian closed 2 years ago

rustatian commented 2 years ago

Reason for This PR

Description of Changes

Config:

fileserver:
  # File server address
  #
  # Error on empty
  address: 127.0.0.1:10101
  # Etag calculation. Request body CRC32.
  #
  # Default: false
  calculate_etag: true

  # Weak etag calculation
  #
  # Default: false
  weak: false

  # Enable body streaming for files more than 4KB
  #
  # Default: false
  stream_request_body: true

  serve:
    # HTTP prefix
    #
    # Error on empty
  - prefix: "/foo"

    # Directory to serve
    #
    # Default: "."
    root: "../../../tests"

    # When set to true, the server tries minimizing CPU usage by caching compressed files
    #
    # Default: false
    compress: false

    # Expiration duration for inactive file handlers. Units: seconds.
    #
    # Default: 10, use a negative value to disable it.
    cache_duration: 10

    # The value for the Cache-Control HTTP-header. Units: seconds
    #
    # Default: 10 seconds
    max_age: 10

    # Enable range requests
    # https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests
    #
    # Default: false
    bytes_range: true

  - prefix: "/foo/bar"
    root: "../../../tests"
    compress: false
    cache_duration: 10
    max_age: 10
    bytes_range: true

License Acceptance

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

PR Checklist

[Author TODO: Meet these criteria.] [Reviewer TODO: Verify that these criteria are met. Request changes if not]

codecov[bot] commented 2 years ago

Codecov Report

Merging #130 (8398ec4) into master (1f1fff3) will increase coverage by 0.11%. The diff coverage is 64.65%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #130      +/-   ##
==========================================
+ Coverage   65.16%   65.27%   +0.11%     
==========================================
  Files         135      137       +2     
  Lines       10816    10907      +91     
==========================================
+ Hits         7048     7120      +72     
- Misses       3058     3074      +16     
- Partials      710      713       +3     
Impacted Files Coverage Δ
fileserver/config.go 0.00% <0.00%> (ø)
http/middleware/static/config.go 66.66% <66.66%> (ø)
fileserver/plugin.go 76.38% <76.38%> (ø)
http/middleware/static/plugin.go 71.02% <81.81%> (ø)
redis/pubsub/pubsub.go 70.54% <0.00%> (-2.33%) :arrow_down:
amqp/amqpjobs/item.go 74.65% <0.00%> (+1.36%) :arrow_up:
beanstalk/beanstalkjobs/item.go 80.00% <0.00%> (+2.85%) :arrow_up:
websockets/executor/executor.go 68.18% <0.00%> (+5.30%) :arrow_up:
tcp/handler/handler.go 57.43% <0.00%> (+6.08%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 1f1fff3...8398ec4. Read the comment docs.

victor-sudakov commented 2 years ago

I don't quite understand the idea. Does this new static files server listen on a port different from http.address? It was great that RR could serve both static and dynamic content on the same port (it worked much like try_files in nginx), but now is that impossible?

rustatian commented 2 years ago

I don't quite understand the idea. Does this new static files server listen on a port different from http.address? It was great that RR could serve both static and dynamic content on the same port (it worked much like try_files in nginx), but now is that impossible?

There are no changes to the existing static files middleware. You may use it as usual and serve static and dynamic content.

rustatian commented 2 years ago

fileserver is a standalone plugin with its own configuration independent from the HTTP plugin.

victor-sudakov commented 2 years ago

fileserver is a standalone plugin with its own configuration independent from the HTTP plugin.

Are you planning to add multiple path/prefix/root support to the static files middleware?

A standalone static file server does not have much value IMHO, as you can always use nginx for that. The real zest is in being able to serve both static and dynamic files from one HTTP endpoint.

rustatian commented 2 years ago

Are you planning to add multiple path/prefix/root support to the static files middleware?

Only after https://github.com/spiral/roadrunner-plugins/issues/32. We can't break behavior for the existing users w/o configuration versioning.

A standalone static file server does not have much value IMHO, as you can always use nginx for that.

For you personally 😃 But not for all RR users.

The real zest is in being able to serve both static and dynamic files from one HTTP endpoint.

Let's see how much interest will be in your FR and if users vote for this feature, I'll raise the priority for it. I'll reopen the original issue.

victor-sudakov commented 2 years ago

A standalone static file server does not have much value IMHO, as you can always use nginx for that.

For you personally smiley But not for all RR users.

Well, I can enumerate all the static prefixes in Ingress configuration and send them to a different service/port. It will just look less graceful :-)

rustatian commented 2 years ago

Yeahh 😄 As for the RR, I'll try to do my best as soon as possible to upgrade the static middleware as we discussed in the ticket, but I have to take into account other users with the tickets with higher priority.