Implementing Datastar: set headers in route

Seems to have been my mistake all along. I was looking at the wrong end and didn’t realize that the route I was calling still had a template/view attached, which means Kirby created a second route that was called right after mine, which is where the response came from. This works perfectly fine in a standalone route:

[
            'pattern' => '/test',
            'action' => function () {
                $sse = new ServerSentEventGenerator();
                $sse->mergeFragments('<div>Foo</div>');
            }
]
2 Likes