Repository: tipsy/javalin (kotlin)

Issue:
Static directories give 404s without adding a trailing slash
**Actual behavior (the bug)**
I'm using Javalin to serve APIs and some static pages.
The pages have been registered in the config via:
```
config.staticFiles.add(staticFile -> {
       staticFile.hostedPath = "/display";
       staticFile.directory = "/frontend/display";
       staticFile.location = Location.CLASSPATH;
});
```
I'm able to access the page via `/display/` and `/display/index.html`, but using `/display` it errors out with "404 Not Found".
I've already added `config.routing.ignoreTrailingSlashes = true;` but it didn't seem to help.

**Expected behavior**
It should ignore the trailing slash and work as intended

**Additional context**
I'm using Java 11 and Javalin 5.6.1

Pull request:
Clone of https://github.com/javalin/javalin/pull/2003 for master.

## Description of changes
- Fixes #1944 - Handling the case when URL path exactly matches the hostedPath of a resource (Reproducible when URL without trailing slash is used to reach a resource with custom hostedPath)
- Added a unit test for this specific case
  - Without the fix, the new test would fail with:
`io.javalin.staticfiles.TestStaticFiles.directory root returns welcome file, when custom hostedPath matches path  Time elapsed: 0.024 s  <<< ERROR!
java.lang.RuntimeException: 
java.lang.Exception: Assertion error: 
expected: 200 OK
 but was: 404 Not Found
	at io.javalin.testing.TestUtil.test(TestUtil.java:38)`

Patch:
diff --git a/javalin/src/main/java/io/javalin/jetty/JettyResourceHandler.kt b/javalin/src/main/java/io/javalin/jetty/JettyResourceHandler.kt
index 44f10b839..443bf5164 100644
--- a/javalin/src/main/java/io/javalin/jetty/JettyResourceHandler.kt
+++ b/javalin/src/main/java/io/javalin/jetty/JettyResourceHandler.kt
@@ -99,6 +99,7 @@ open class ConfigurableHandler(val config: StaticFileConfig, jettyServer: Server
                 if (config.aliasCheck?.check(path, aliasResource) == true) aliasResource else throw AccessDeniedException("Failed alias check")
 
             config.hostedPath == "/" -> super.getResource(path) // same as regular ResourceHandler
+            path == config.hostedPath -> super.getResource("/")
             path.startsWith(config.hostedPath + "/") -> super.getResource(path.removePrefix(config.hostedPath))
             else -> EmptyResource.INSTANCE // files that don't start with hostedPath should not be accessible
         }


Test patch:
diff --git a/javalin/src/test/java/io/javalin/staticfiles/TestStaticFiles.kt b/javalin/src/test/java/io/javalin/staticfiles/TestStaticFiles.kt
index 1f74524a3..f06f8243b 100644
--- a/javalin/src/test/java/io/javalin/staticfiles/TestStaticFiles.kt
+++ b/javalin/src/test/java/io/javalin/staticfiles/TestStaticFiles.kt
@@ -176,13 +176,31 @@ class TestStaticFiles {
     }
 
     @Test
-    fun `directory root return welcome file if there is a welcome file`() = TestUtil.test(defaultStaticResourceApp) { _, http ->
+    fun `directory root returns welcome file`() = TestUtil.test(defaultStaticResourceApp) { _, http ->
         assertThat(http.get("/subdir/").httpCode()).isEqualTo(OK)
         assertThat(http.getBody("/subdir/")).isEqualTo("<h1>Welcome file</h1>")
         assertThat(http.get("/subdir").httpCode()).isEqualTo(OK)
         assertThat(http.getBody("/subdir")).isEqualTo("<h1>Welcome file</h1>")
     }
 
+    @Test
+    fun `directory root returns welcome file, when custom hostedPath matches path`() {
+        val staticWithCustomHostedPath = Javalin.create { config ->
+            config.staticFiles.add {
+                it.directory = "/public/subdir"
+                it.location = Location.CLASSPATH
+                it.hostedPath = "/subdir"
+            }
+        }
+
+        return TestUtil.test(staticWithCustomHostedPath) { _, http ->
+            assertThat(http.get("/subdir/").httpCode()).isEqualTo(OK)
+            assertThat(http.getBody("/subdir/")).isEqualTo("<h1>Welcome file</h1>")
+            assertThat(http.get("/subdir").httpCode()).isEqualTo(OK)
+            assertThat(http.getBody("/subdir")).isEqualTo("<h1>Welcome file</h1>")
+        }
+    }
+
     @Test
     fun `welcome files work without trailing slashes on hosted path`() = TestUtil.test(Javalin.create {
         it.staticFiles.add {