helidon-io / helidon

Java libraries for writing microservices
https://helidon.io
Apache License 2.0
3.52k stars 564 forks source link

4.x: Static content from classpath improvements #9471

Open tomas-langer opened 1 week ago

tomas-langer commented 1 week ago

Currently we generate temporary files for extracted jar entries as ws-****.je

A few improvements could be done:

hrstoyanov commented 4 days ago

Is it possible to process the files as they are extracted from the class path? For example, CSS files may have comments, that I might not want to serve to the client , and would like to strip off.

tomas-langer commented 4 days ago

Is it possible to process the files as they are extracted from the class path? For example, CSS files may have comments, that I might not want to serve to the client , and would like to strip off.

I think this should be done at build time and your deployment should contain the files you want to serve (minified css, javascript etc.).

Also Helidon does not have such a feature, as we need to work with the content length of the file (i.e. when a range is requested, to correctly provide Content-Length header etc.). Such operations would introduce quite an overhead (I can imagine this being implemented, but I would rather not)

tomas-langer commented 4 days ago

The PR will have the following updates:

Example of a configuration:

server:
  features:
    # the new static content feature, automatically discovered
    static-content:
      # (optional) configuration of temporary storage
      temporary-storage:
        directory: "./target/helidon/tmp"
        file-prefix: "helidon-custom"
        file-suffix: ".cache"
        # delete-on-exit: false
      # classpath handlers (context to serve on webserver and location on classpath)
      classpath:
        - context: "/classpath"
          location: "web"
        - context: "/singleclasspath"
          location: "web/resource.txt"
      # file system handlers (context to serve on webserver and location on file system)
      path:
        - context: "/path"
          location: "./src/test/resources/web"
        - context: "/singlepath"
          location: "./src/test/resources/web/resource.txt"