Skip to content

Commit

Permalink
serve assets inside a path
Browse files Browse the repository at this point in the history
  • Loading branch information
Alessio Coser committed Jan 28, 2020
1 parent cf6fae1 commit 05c8510
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/daikon/HttpServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class HttpServer(private val port: Int = 4545, initializeActions: HttpServer.()
fun assets(path: String): HttpServer {
val servletHolder = ServletHolder(DefaultServlet())
handler.addServlet(servletHolder, path)
handler.addServlet(servletHolder, joinPaths(path))
handler.baseResource = Resource.newResource(HttpServer::class.java.getResource("/assets/"))
return this
}
Expand Down
20 changes: 15 additions & 5 deletions src/test/kotlin/daikon/HttpRoutingTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,21 @@ class HttpRoutingTest {
@Test
fun `mix of static file and dynamic routes`() {
HttpServer()
.get("/bar/2") { _, res -> res.write("Hello") }
.assets("/foo/*")
.start().use {
assertThat(get("/foo/style.css").text).isEqualTo("body {}")
assertThat(get("/bar/2").text).isEqualTo("Hello")
.get("/bar/2") { _, res -> res.write("Hello") }
.assets("/foo/*")
.start().use {
assertThat(get("/foo/style.css").text).isEqualTo("body {}")
assertThat(get("/bar/2").text).isEqualTo("Hello")
}
}

@Test
fun `serve assets inside a path`() {
HttpServer()
.path("/foo") {
assets("/bar/*")
}.start().use {
assertThat(get("/foo/bar/style.css").text).isEqualTo("body {}")
}
}

Expand Down
1 change: 1 addition & 0 deletions src/test/resources/assets/foo/bar/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
body {}

0 comments on commit 05c8510

Please sign in to comment.