static serving from resources after assembly fails
siddhartha-gadgil opened this issue · 9 comments
In https://github.com/siddhartha-gadgil/MillScalaServer (and also a larger project, which is what I wanted), serving from resources works fine with server.run
and server.runBackground
but fails on running the result of server.assembly
- Even files in the
resources
folder behave the same way.
In the following code in cask, relPath
is defined but not used.
val relPath = java.nio.file.Paths.get(path)
val (data0, statusCode0) = resourceRoot.getResourceAsStream(path) match{
case null => ("": Response.Data, 404)
case res => (res: Response.Data, 200)
}
is that a typo (which accidentally does not matter in run
)?
It seems to work fine with the example project:
@cask.staticResources("/static/resource")
def staticResourceRoutes() = "cask"
Perhaps it's something to do with the way your app has
@cask.staticResources("/public")
def staticResourceRoutes() = "."
?
Not sure what "."
means w.r.t. JVM resources, but maybe it doesn't like it in some cases
Fixed in the toy project. Thanks a lot.
I'll confirm in the larger project and close
It is indeed fixed. Thanks again.
For anyone who gets here with similar problem:
I had errors 404 with server not being able to locate images by path that should have worked
that turned out to be a problem with browser - it was caching 404 from builds that were incorrect
i've been able troubleshoot that by not trusting initial 404 responses, and manually triggering "Resend" in the Network console
And before that i checked "jar tf stripe-0.0.1-SNAPSHOT.jar | grep public" to see if my 'public' dir is indeed in the assembly jar
Overall the function works as should be expected
'src/main/resources' is root, and for example to server 'src/main/resources/public' the method should return "public"