Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.

Commit 95e4f4d

Browse files
committed
Assets resolving in dev mode (1.4.0 release) fix jooby-project#1122
1 parent 569fe81 commit 95e4f4d

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

modules/jooby-assets/src/main/java/org/jooby/assets/Assets.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,9 @@ public void configure(final Env env, final Config config, final Binder binder) t
516516
// live compiler?
517517
AssetHandler handler;
518518
if (watch) {
519+
Path publicDir = Paths.get(conf.getString("user.dir"), "public");
519520
Path workdir = Paths.get(conf.getString("assets.outputDir"));
520-
handler = new FileSystemAssetHandler("/", workdir);
521+
handler = new FileSystemAssetHandler("/", workdir, publicDir);
521522
LiveCompiler liveCompiler = new LiveCompiler(compiler, workdir);
522523

523524
routes.use("*", "*", liveCompiler)

modules/jooby-assets/src/main/java/org/jooby/internal/assets/FileSystemAssetHandler.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,23 +203,30 @@
203203
*/
204204
package org.jooby.internal.assets;
205205

206+
import static org.jooby.funzy.Throwing.throwingFunction;
206207
import org.jooby.handlers.AssetHandler;
207208

208209
import java.net.URL;
209210
import java.nio.file.Files;
210211
import java.nio.file.Path;
212+
import java.util.Arrays;
213+
import java.util.List;
211214

212215
public class FileSystemAssetHandler extends AssetHandler {
213216

214-
private final Path workdir;
217+
private final List<Path> sources;
215218

216-
public FileSystemAssetHandler(final String pattern, final Path workdir) {
219+
public FileSystemAssetHandler(final String pattern, final Path... sources) {
217220
super(pattern);
218-
this.workdir = workdir;
221+
this.sources = Arrays.asList(sources);
219222
}
220223

221224
@Override protected URL resolve(String path) throws Exception {
222-
Path file = workdir.resolve(path);
223-
return Files.exists(file) ? file.toUri().toURL() : null;
225+
return sources.stream()
226+
.map(source -> source.resolve(path))
227+
.filter(Files::exists)
228+
.findFirst()
229+
.map(throwingFunction(it -> it.toUri().toURL()))
230+
.orElse(null);
224231
}
225232
}

modules/jooby-assets/src/test/java/org/jooby/assets/AssetsTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public class AssetsTest {
9797
@Test
9898
public void configure() throws Exception {
9999
Config conf = ConfigFactory.empty()
100+
.withValue("user.dir", ConfigValueFactory.fromAnyRef(System.getProperty("user.dir")))
100101
.withValue("application.path", ConfigValueFactory.fromAnyRef("/path"))
101102
.withValue("assets.etag", ConfigValueFactory.fromAnyRef(true))
102103
.withValue("assets.outputDir",
@@ -123,6 +124,7 @@ public void configure() throws Exception {
123124
@Test
124125
public void configureRestart() throws Exception {
125126
Config conf = ConfigFactory.empty()
127+
.withValue("user.dir", ConfigValueFactory.fromAnyRef(System.getProperty("user.dir")))
126128
.withValue("application.path", ConfigValueFactory.fromAnyRef("/path"))
127129
.withValue("assets.etag", ConfigValueFactory.fromAnyRef(true))
128130
.withValue("assets.outputDir",
@@ -151,6 +153,7 @@ public void configureRestart() throws Exception {
151153
@Test
152154
public void configureProdDist() throws Exception {
153155
Config conf = ConfigFactory.empty()
156+
.withValue("user.dir", ConfigValueFactory.fromAnyRef(System.getProperty("user.dir")))
154157
.withValue("application.env", ConfigValueFactory.fromAnyRef("prod"))
155158
.withValue("assets.etag", ConfigValueFactory.fromAnyRef(true))
156159
.withValue("application.path", ConfigValueFactory.fromAnyRef("/"))

0 commit comments

Comments
 (0)