refactor(core): make boot and middleware ordering deterministic
CI / Build & Test (push) Failing after 4m51s
CI / Build & Test (pull_request) Canceled after 23s

This commit is contained in:
Zakaria El Orche
2026-08-12 16:42:49 +00:00
parent d7f36a7aea
commit 891ef99b8e
51 changed files with 1395 additions and 504 deletions
@@ -57,15 +57,17 @@ public final class JteExtension extends BaseViewExtension<JteTarget> {
}
@Override
public void routes(FlashRegistrar<?> app, FlashContext ctx) {
if (!settings.serveStatics()) return;
JteStaticServing staticServing = JteStaticServing.load(settings);
if (staticServing == null) return;
String wildcard = settings.staticPrefix() + "/**";
StaticJteHandler handler = new StaticJteHandler(staticServing);
app.get(wildcard, handler::handle);
app.head(wildcard, (req, res) -> { staticServing.serve(req, res, true); return null; });
public void configure(FlashRegistrar<?> app, FlashContext ctx) {
super.configure(app, ctx);
ctx.onReady(() -> {
if (!settings.serveStatics()) return;
JteStaticServing staticServing = JteStaticServing.load(settings);
if (staticServing == null) return;
String wildcard = settings.staticPrefix() + "/**";
StaticJteHandler handler = new StaticJteHandler(staticServing);
app.get(wildcard, handler::handle);
app.head(wildcard, (req, res) -> { staticServing.serve(req, res, true); return null; });
});
}
@Override
@@ -93,7 +93,9 @@ class JteExtensionTest {
void routes_register_static_wildcard_when_enabled() {
JteExtension ext = new JteExtension(cfg -> cfg.staticPrefix("/assets"));
TestRegistrar app = new TestRegistrar();
ext.routes(app, new dev.relism.flash.extension.FlashContext());
dev.relism.flash.extension.FlashContext ctx = new dev.relism.flash.extension.FlashContext();
ext.configure(app, ctx);
ctx.complete();
assertTrue(app.routes.containsKey("GET /assets/**"));
assertTrue(app.routes.containsKey("HEAD /assets/**"));
}
@@ -102,7 +104,9 @@ class JteExtensionTest {
void routes_do_not_register_static_when_disabled() {
JteExtension ext = new JteExtension().serveStatics(false);
TestRegistrar app = new TestRegistrar();
ext.routes(app, new dev.relism.flash.extension.FlashContext());
dev.relism.flash.extension.FlashContext ctx = new dev.relism.flash.extension.FlashContext();
ext.configure(app, ctx);
ctx.complete();
assertTrue(app.routes.isEmpty());
}
@@ -112,7 +116,9 @@ class JteExtensionTest {
.staticPrefix("/assets")
.largeFileThresholdBytes(1));
TestRegistrar app = new TestRegistrar();
ext.routes(app, new dev.relism.flash.extension.FlashContext());
dev.relism.flash.extension.FlashContext ctx = new dev.relism.flash.extension.FlashContext();
ext.configure(app, ctx);
ctx.complete();
Request req = request("/assets/sample.css", null, null, null);
Response res = new Response(200, dev.relism.flash.http.ContentType.TEXT_PLAIN);
@@ -161,7 +167,7 @@ class JteExtensionTest {
private static final class TestRegistrar extends dev.relism.flash.extension.FlashRegistrar<TestRegistrar> {
private final Map<String, RequestHandler> routes = new HashMap<>();
private final List<dev.relism.flash.routing.Middleware> mws = new ArrayList<>();
private final List<dev.relism.flash.routing.MiddlewareNode> mws = new ArrayList<>();
@Override
public dev.relism.flash.extension.FlashContext ctx() {
@@ -169,7 +175,7 @@ class JteExtensionTest {
}
@Override
protected void addRoute(dev.relism.flash.http.HttpMethod method, String path, RequestHandler handler, List<dev.relism.flash.routing.Middleware> mw) {
protected void addRoute(dev.relism.flash.http.HttpMethod method, String path, RequestHandler handler, List<dev.relism.flash.routing.MiddlewareNode> mw) {
routes.put(method.name() + " " + path, handler);
}
@@ -179,7 +185,7 @@ class JteExtensionTest {
}
@Override
protected void addMiddleware(dev.relism.flash.routing.Middleware mw) {
protected void addMiddleware(dev.relism.flash.routing.MiddlewareNode mw) {
mws.add(mw);
}
}