Closed RyanSusana closed 5 years ago
Hi @RyanSusana. I'm guessing this is because StaticFilesFolder
has static variables:
private static volatile String local;
private static volatile String external;
Are there any plans on changing this or must I resort to multiple JVM's?
Maybe we can make it per Service instance instead? Or is this not possible?
It's possible. Spark used to be completely static, so I'm guessing this is just a "leftover". It should be possible to fix, but it would break backwards compatibility for anyone actually relying on this behavior 🤔
Why would it break backwards compatability?
Any change in current behavior is really a change in backwards compatibility. I don't remember what the current behavior is, but based on reading the code it looks like you can do:
val serviceA = ignite().apply { staticFiles.location("/public") }
val serviceB = ignite()
Then do a GET
for static files to serviceB
. If this is the case, people will have to add staticFiles.location("/public")
to their second service too.
I'll fire up IntelliJ and check.
It didn't work without calling staticFiles.location()
, so that's good. Also, I found some strange behavior:
Works:
Service serviceA = Service.ignite();
serviceA.port(4001);
serviceA.staticFiles.location("/public/pages");
serviceA.init();
serviceA.awaitInitialization();
Service serviceB = Service.ignite();
serviceB.staticFiles.location("/public");
serviceB.port(4002);
serviceB.init();
Bad request:
Service serviceA = Service.ignite();
serviceA.port(4001);
serviceA.staticFiles.location("/public");
serviceA.init();
serviceA.awaitInitialization();
Service serviceB = Service.ignite();
serviceB.staticFiles.location("/public/pages");
serviceB.port(4002);
serviceB.init();
This can be fixed as a bug then, I can't imagine anyone really relying on this behavior.
Thank you for the help!
Fixed by #1036
Hello friends,
I have been using sparkjava for a while now and am developing a framework (Elepy using your framework.
The problem that I am running into is that when I have multiple jars with static resources on different Services, I get a Bad Request 400 on all but the first staticfile location. The different Services are hosted on port 80 and 1337 and get instantiated with ignite()
This means that per JVM I can only have one staticfile location? It does recognize that the resource exists, otherwise it would give me a 404 instead.
I looked through the source code and it has something to do with DirectoryTraversalDetection.